Skip to content

alias __setattr__ to __setitem__ in Results#3281

Merged
lilyminium merged 8 commits intoMDAnalysis:developfrom
lilyminium:results-getattr
May 7, 2021
Merged

alias __setattr__ to __setitem__ in Results#3281
lilyminium merged 8 commits intoMDAnalysis:developfrom
lilyminium:results-getattr

Conversation

@lilyminium
Copy link
Member

@lilyminium lilyminium commented May 7, 2021

Fixes #3282

Changes made in this Pull Request:

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

@codecov
Copy link

codecov bot commented May 7, 2021

Codecov Report

Merging #3281 (dc7c0f1) into develop (8deaa1e) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3281      +/-   ##
===========================================
- Coverage    93.03%   93.03%   -0.01%     
===========================================
  Files          172      172              
  Lines        22732    22731       -1     
  Branches      3194     3192       -2     
===========================================
- Hits         21149    21148       -1     
  Misses        1533     1533              
  Partials        50       50              
Impacted Files Coverage Δ
package/MDAnalysis/analysis/base.py 96.61% <100.00%> (-0.03%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8deaa1e...dc7c0f1. Read the comment docs.

@lilyminium lilyminium requested a review from PicoCentauri May 7, 2021 02:51
@orbeckst orbeckst requested a review from cbouy May 7, 2021 03:02
Copy link
Contributor

@PicoCentauri PicoCentauri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a smart PR!

Comment on lines -101 to +100
super().__init__(**kwargs)
self._dict_frozen = True
self.__dict__["data"] = {}
self.update(kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UserDict allow to initlize the instance with passing a dictionary. This does not work anymore. I suggest you copy the four lines

if dict is not None:
    self.update(dict)
if kwargs:
    self.update(kwargs)

from cpython, adjust the arguments, add a test and everything is fine.

Copy link
Member Author

@lilyminium lilyminium May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally!

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

(I was debating if we should have a test showing that two instances do not interfere with each other but that seems un-necessary with the current implementation — it just makes use of the way that Python resolves class and instance attribute access.)

@orbeckst
Copy link
Member

orbeckst commented May 7, 2021

@PicoCentauri are you happy with the changes?

@PicoCentauri @lilyminium please merge when ready.

@orbeckst orbeckst added this to the 2.0 milestone May 7, 2021
@lilyminium
Copy link
Member Author

Should I update CHANGELOG? The Results PR itself was very recent.

@orbeckst
Copy link
Member

orbeckst commented May 7, 2021

I'd say no — normally we update CHANGELOG for anything that has an associated issue. But in this case this is a hotfix and the CHANGELOG entry would be more confusing than anything else.

@lilyminium
Copy link
Member Author

I'll leave this open for another few hours in case @cbouy or @PicoCentauri have comments :)

Copy link
Member

@cbouy cbouy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry didn't get much time but all looks good!

@lilyminium lilyminium changed the title Allow Results to modify setattr'ed items with setitem alias __setattr__ to __setitem__ in Results May 7, 2021
@lilyminium lilyminium merged commit be3ec1b into MDAnalysis:develop May 7, 2021
@lilyminium lilyminium deleted the results-getattr branch May 7, 2021 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Current Results class has a conflict in key validation between setattr and setitem

5 participants