-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MNT: make _setattr_cm more conservative #17620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MNT: make _setattr_cm more conservative #17620
Conversation
CI does not like this at all. |
Indeed, I thought I ran the tests before I pushed. I must have lost track of what I was doing locally... |
4111ab6
to
d0849a6
Compare
🤦 I edited one working tree and installed and tested a different one. |
d0849a6
to
3b4da04
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what features we should be supporting in the future (re: #17561), but at least this makes it clear what we don't.
lib/matplotlib/cbook/__init__.py
Outdated
origs = {} | ||
for attr in kwargs: | ||
orig = getattr(obj, attr, sentinel) | ||
# monkey patching on a new attribute, this is OK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps you can reorder this to make the common case first, e.g.
if (attr in obj.__dict__ or orig is sentinel
or isinstance(getattr(type(obj), attr), (property, types.FunctionType)):
origs[attr] = orig
else:
raise ValueError(...)
Checking to types.FunctionType in the type is the same as checking for methods, and (as noted in the other PR, I think) won't give a wrong result if an unrelated bound method is assigned as instance var (self.foo = otherobj.method
) -- at least I think this point should be fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. I agree the method from another object is a valid concern (sorry I didn't fully register it before).
6ee399a
to
756b9c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just style things.
- special case methods and properties because they are descriptors - fail on any other non-instance attribute
756b9c3
to
9e88fa5
Compare
PR Summary
This is a simpler version of #17561
PR Checklist