Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • docs.python.org/2/library/functions.html#locals locals() should not be modified (it may affect the interpreter, in your case, removing self from the calling function's scope)
    – MWB
    Commented Dec 11, 2016 at 1:27
  • @MaxB From the docs you cite: ... changes may not affect the values of local and free variables used by the interpreter. self is still available in __init__ . Commented Dec 11, 2016 at 2:28
  • Right, the reader expects it to affect the local variables, but it may or may not, depending on a number of circumstances. The point is that it's UB.
    – MWB
    Commented Dec 11, 2016 at 2:30
  • Quote: "The contents of this dictionary should not be modified"
    – MWB
    Commented Dec 11, 2016 at 2:32
  • @MaxB I added a version that does not change locals(). Commented Dec 11, 2016 at 2:57