[New-bugs-announce] [issue45333] += operator and accessors bug?

chovey report at bugs.python.org
Thu Sep 30 11:54:52 EDT 2021

New submission from chovey <chovey at sandia.gov>:

We used get/set attribute accessors with private data, and suspect the beaviour we see with the += operator contains a bug.  Below is our original implementation, followed by our fix.  But, we feel the original implementation should have worked.  Please advise.  Thank you.

    def position(self) -> np.ndarray:
        return self._position

    def position(self, val: np.ndarray):
        self._position = val

    def update(self, *, delta_t: float):
        # Nope! Bug! (?)  
        # Tried to combine the getter and setter for self.position
        # with the += operator, which will not work.
        # self.position += self.velocity * delta_t
        # This fixes the behaviour.
        self._position = self.velocity * delta_t + self.position

components: 2to3 (2.x to 3.x conversion tool)
messages: 402966
nosy: chovey
priority: normal
severity: normal
status: open
title: += operator and accessors bug?
type: behavior
versions: Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list