GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — bpo-35105: Document that CPython accepts "invalid" identifiers by Windsooon · Pull Request #11263 · python/cpython Conversation
|
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Do we really need to mention this? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
That discussion is on the issue. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can mark this as an implementation detail for setattr(). The details are downstream and determined by the target object, not by setattr itself.
Suggested wording:
Note, setattr() attempts to update the object with the given attr/value pair.
Whether this succeeds and what its affect is is determined by the target object.
If an object's class defines `__slots__`, the attribute may not be writeable.
If an object's class defines property with a setter method, the *setattr()*
will trigger the setter method which may or may not actually write the attribute.
For objects that have a regular dictionary (which is the typical case), the
*setattr()* call can make any string keyed update allowed by the dictionary
including keys that aren't valid identifiers -- for example setattr(a, '1', 'one')
will be the equivalent of vars()['1'] ='one'.
This issue has little to do with setattr() and is more related to the fact that instance dictionaries can hold any valid key. In a way, it is no different than a user writing a.__dict__['1'] = 'one'. That has always been allowed and the __dict__ attribute is documented as writeable, so a user is also allowed to write `a.dict = {'1': 'one'}.
In short, we can talk about this in the setattr() docs but it isn't really a setattr() issue. Also, the behavior is effectively guaranteed by the other things users are allowed to do, so there is no merit in marking this as an implementation detail. Non-identifier keys can make it into an instance dictionary via multiple paths that are guaranteed to work.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I agree with Raymond's revision. Note that it would replace the entire proposed addition, including the impl-detail directive. By adding more 'meat', it makes an addition more worthwhile. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The whole note needs to be indented for proper alignment.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Hi @Windsooon thanks for this PR! Would you have some time to integrate Cheryl comments? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I just updated it. Thank you @csabella |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nits (all can be accepted right from github).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| .. note:: | ||
|
|
||
| setattr() attempts to update the object with the given attr/value pair. |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| setattr() attempts to update the object with the given attr/value pair. | |
| ``setattr()`` attempts to update the object with the given attr/value pair. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| setattr() attempts to update the object with the given attr/value pair. | ||
| Whether this succeeds and the effect it has determined by the target object. | ||
| If an object's class defines `__slots__`, the attribute may not be writeable. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| If an object's class defines `__slots__`, the attribute may not be writeable. | |
| If an object's class defines ``__slots__``, the attribute may not be writeable. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| For objects that have a regular dictionary (which is the typical case), the | ||
| *setattr()* call can make any string keyed update allowed by the dictionary | ||
| including keys that aren't valid identifiers -- for example ``setattr(a, '1', 'one')`` | ||
| will be the equivalent of ``vars()['1'] ='one'``. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| will be the equivalent of ``vars()['1'] ='one'``. | |
| will be the equivalent of ``vars()['1'] = 'one'``. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@Windsooon, please address the review comments from Julien. Thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Changes were requested on this PR by a core dev over two years ago, but have not been applied. There is also now a merge conflict. I am therefore closing this PR. @Windsooon, if you're still interested in working on this, feel free to open a new PR. Alternatively, ping me, and I'll happily reopen the PR. Thanks! 🙂 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@AlexWaygood I'm so sorry for missing the notification from CPython, I will catch up in a few weeks. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@Windsooon no worries! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| .. note:: | ||
|
|
||
| setattr() attempts to update the object with the given attr/value pair. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
(in addition to the above)
| setattr() attempts to update the object with the given attr/value pair. | |
| setattr() attempts to update the object with the given attribute/value pair. |
or
| setattr() attempts to update the object with the given attr/value pair. | |
| setattr() attempts to update the object with the given attribute-value pair. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| .. note:: | ||
|
|
||
| setattr() attempts to update the object with the given attr/value pair. | ||
| Whether this succeeds and the effect it has determined by the target object. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| Whether this succeeds and the effect it has determined by the target object. | |
| Whether this succeeds and the effect it has is determined by the target object. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| setattr() attempts to update the object with the given attr/value pair. | ||
| Whether this succeeds and the effect it has determined by the target object. | ||
| If an object's class defines `__slots__`, the attribute may not be writeable. | ||
| If an object's class defines :class:`property` with a setter method, the *setattr()* |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
*setattr()* -> `setattr()` here and below (I think * is commonly used for parameters)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| will trigger the setter method which may or may not actually write the attribute. | ||
| For objects that have a regular dictionary (which is the typical case), the | ||
| *setattr()* call can make any string keyed update allowed by the dictionary | ||
| including keys that aren't valid identifiers -- for example ``setattr(a, '1', 'one')`` |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Would you happen to have an example of this behavior? I'm not quite following what it's doing (how a turns into vars())
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| If an object's class defines :class:`property` with a setter method, the *setattr()* | ||
| will trigger the setter method which may or may not actually write the attribute. | ||
| For objects that have a regular dictionary (which is the typical case), the | ||
| *setattr()* call can make any string keyed update allowed by the dictionary |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| *setattr()* call can make any string keyed update allowed by the dictionary | |
| *setattr()* call can make any string-keyed update allowed by the dictionary |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think this PR has now been superseded by #96454 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.