Skip to content

Add description of special case to "Assignment statements" section #49871

Closed

Description

@jjposner
mannequin
BPO 5621
Nosy @birkenfeld
Files
  • assignment_statement.diff: patch file created with svn diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/birkenfeld'
    closed_at = <Date 2009-09-16.10:13:15.327>
    created_at = <Date 2009-03-31.14:45:05.467>
    labels = ['docs']
    title = 'Add description of special case to "Assignment statements" section'
    updated_at = <Date 2009-09-16.10:13:15.326>
    user = 'https://bugs.python.org/jjposner'

    bugs.python.org fields:

    activity = <Date 2009-09-16.10:13:15.326>
    actor = 'georg.brandl'
    assignee = 'georg.brandl'
    closed = True
    closed_date = <Date 2009-09-16.10:13:15.327>
    closer = 'georg.brandl'
    components = ['Documentation']
    creation = <Date 2009-03-31.14:45:05.467>
    creator = 'jjposner'
    dependencies = []
    files = ['14861']
    hgrepos = []
    issue_num = 5621
    keywords = ['patch']
    message_count = 6.0
    messages = ['84790', '84800', '84805', '84822', '92420', '92677']
    nosy_count = 2.0
    nosy_names = ['georg.brandl', 'jjposner']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue5621'
    versions = ['Python 2.6', 'Python 3.0']

    Activity

    1. jjposner commented on Mar 31, 2009

      jjposnermannequin
      MannequinAuthor

      The subsection "Augmented assignment statements" includes a note on this
      special case:

      a.x += 1

      But the parent section "Assignment statements" does not include such a
      note, even though it's essentially the same situation. I suggest
      replacing the bulleted paragraph that begins "If the target is an
      attribute reference" with the following:

      ---------

      • If the target is an attribute reference: The primary expression in
        the reference is evaluated. It should yield an object with
        assignable attributes; if this is not the case, TypeError is raised.
        That object is then asked to assign the assigned object to the given
        attribute; if it cannot perform the assignment, it raises an
        exception (usually but not necessarily AttributeError).

        If the object is a class instance and the attribute
        reference occurs on both sides of the assignment operator; for example::

              a.x = a.x + 1
      ... in the RHS expression, ``a.x`` is evaluated with
      ``getattr()``, which can access either an instance attribute or (if
      no instance attribute exists) a class attribute. The LHS target
      ``a.x`` is assigned with ``setattr()``, which *always* accesses
      an instance attribute, creating it if necessary. Thus, the two
      occurrences of ``a.x`` do not necessarily refer to the same
      variable. If the RHS expression refers to a class attribute, the LHS
      creates a new instance attribute as the target of the assignment.
      (This description does not necessarily
      apply to attributes defined with ``property()``, which are accessed
      with user-defined functions instead of ``getattr()`` and ``setattr()``).
      
      See section "Augmented assignment statements" for a similar note on
      attribute references.
      

      ---------

    2. added
      docs
      on Mar 31, 2009
    3. birkenfeld commented on Mar 31, 2009

      @birkenfeld
      Member

      I'm not sure it belongs there, since normal assignments do not say
      *anything* about the RHS.

    4. jjposner commented on Mar 31, 2009

      jjposnermannequin
      MannequinAuthor

      The "Assignment statements" section *does* talk about the RHS -- but in
      a subtle way:

      For targets which are attribute references, the initial
      value is retrieved with a getattr()

      The retrieving of the initial value (maybe "current value" would be
      better) occurs on the RHS of the assignment statement.

    5. birkenfeld commented on Mar 31, 2009

      @birkenfeld
      Member

      Yes, it says that getattr() is used in the section about augassign; but
      there the note you refer to is already present.

    6. jjposner commented on Sep 8, 2009

      jjposnermannequin
      MannequinAuthor

      George, here is a patch file for this bug. It modifies file
      doc/reference/simple_stmts.rst

      Please let me know if this was the wrong way to submit the patch file.

    7. birkenfeld commented on Sep 16, 2009

      @birkenfeld
      Member

      The patch submission was correct.

      I edited the patch a bit, moved the example from augmented assignment to
      the regular assignment and added a link from there to the new section.

      Committed in r74822.

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    docs

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions