-
Notifications
You must be signed in to change notification settings - Fork 1.3k
object has different identities during and after import #2687
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
Comments
I think the correct thing would be to have the later id of I do agree that this is a long lived issue because we assume that only one reference of module variable exist. (We recurse from the module dict down and don't look elsewhere for references.) I don't think this is urgent and would argue for it to be "Long Term" because there is a simple and easy workaround: Just assign |
@tannewt I agree it should be ling term. I think very few people will find this bug and the temporary fix is quite easy. It could be that I am miss-interpreting "the correct thing would be to have the later id of l[0] be 536896144": to me, this seems intuitively correct because any import in python is really just syntactic sugar for the import function for |
meta importers and other CPython extensibilities aside |
It's not meant to be a copy (that is the bug). It is meant to be a move. The id will change but it will change consistently between the two objects. If you add a function that will print the id from within the module's scope then the new id should be there as well. The object is moved at the end of the import and the existing prints are before that. |
Ah, I did misinterpret. |
Restating this without use of Put the following in # content of nested.py
l = [[]]
l0 = l[0] and the following in # runtime
import nested
nested.l0.append("test")
print(nested.l) With python3, it prints |
Fixed by #8281, which removed long-lived allocations, and so removed objects moving around after creation. |
nested.py:
In CircuitPython 2.x, MicroPython, and CPython the
id()
values are the same in the REPL. My guess is that this has to do with making an object long-lived during compilation, since this shows up in 3.x.Thanks @TG-Techie for spotting this. This is reduced from a real program, in which he was fetching and assigning some empty lists nested inside some tuples during an import, and then found out they were not the same lists when referenced by subscript outside.
Tagging @tannewt.
The text was updated successfully, but these errors were encountered: