Skip to content

bpo-35105: Document that CPython accepts "invalid" identifiers #11263

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,17 @@ are always available. They are listed here in alphabetical order.
object allows it. For example, ``setattr(x, 'foobar', 123)`` is equivalent to
``x.foobar = 123``.

.. note::

setattr() attempts to update the object with the given attr/value pair.
Copy link
Member

@JulienPalard JulienPalard Sep 12, 2019

Choose a reason for hiding this comment

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

Suggested change
setattr() attempts to update the object with the given attr/value pair.
``setattr()`` attempts to update the object with the given attr/value pair.

Copy link
Contributor

Choose a reason for hiding this comment

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

(in addition to the above)

Suggested change
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

Suggested change
setattr() attempts to update the object with the given attr/value pair.
setattr() attempts to update the object with the given attribute-value pair.

Whether this succeeds and the effect it has determined by the target object.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

If an object's class defines `__slots__`, the attribute may not be writeable.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

If an object's class defines :class:`property` with a setter method, the *setattr()*
Copy link
Contributor

Choose a reason for 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)

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
*setattr()* call can make any string keyed update allowed by the dictionary
*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')``
Copy link
Contributor

Choose a reason for 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())

will be the equivalent of ``vars()['1'] ='one'``.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
will be the equivalent of ``vars()['1'] ='one'``.
will be the equivalent of ``vars()['1'] = 'one'``.


.. class:: slice(stop)
slice(start, stop[, step])
Expand Down