5
halfflat
233d

So I get that python's scope/mutability/binding semantics are … idiosyncratic.

But 'a += b' may or may not rebind the name 'a' DEPENDING ON ITS DYNAMIC TYPE.

Yeah, that makes total sense. Much intuit. So design.

Comments
  • 0
    do you mean that "a (type A) + b (type B)" can be of type B? Thats old.
  • 0
    @stop No, not really.

    In one case, `id(a)` will be the same before and after; in another, `id(a)` will differ.
  • 0
    @halfflat For the same a? That would be news to me, could you please give an explicit example?
  • 0
    Can you give me an example of where the IDs are the same?
  • 0
    @Godisalie @retnikt

    def sameid(x): oldid = id(x); x += x; print(oldid==id(x))

    a = "one"; sameid(a)

    b = [1]; sameid(b)
  • 0
    nnever had this happen in Py2, some kinda bug in Py3?
  • 1
    @halfflat well in that example you are appending to a list. If the current space cannot consecutively hold all the new elements, it needs to be moved. Makes sense to me.
  • 0
    @deadPix3l It's consistent with the other peculiar choices Python has made regarding names, scopes, and objects.

    But it's really weird, coming at it from the outside: the statement not only mixes an operation on an object with something that changes the current scope (which is odd), it does so contingently (which is really, really odd).
  • 0
    @Parzi Same in Python2. It's not a bug, it's intentional. (!)
Add Comment