-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
When experimenting with file IO, I found out that when opening a file, one always initializes the io
module from scratch (and then, when importing it, one initializes it exactly once, no matter how many times it’s been already initialized), making checking if objects are instances of given classes from that module impossible, as those classes are represented by different memory objects, eg.:
>>>>> file = open('/tmp/tst')
>>>>> file.buffer
<BufferedReader object at 0x55658e5c30e0>
>>>>> type(file.buffer)
<class 'BufferedReader'>
>>>>> import io
>>>>> io.BufferedReader
<class 'BufferedReader'>
>>>>> type(file.buffer) is io.BufferedReader
False
>>>>> type(file.buffer) == io.BufferedReader
False
>>>>> from io import BufferedReader # subsequent imports from the module do not cause that
>>>>> BufferedReader is io.BufferedReader
True
>>>>> id(type(file.buffer))
93894668449408
>>>>> id(BufferedReader)
93894668474000
It seems this is the only module affected by this behaviour (all the other mk_module(&ctx)
functions are afaik used only in the module_inits
hash map used for import initialization).
Metadata
Metadata
Assignees
Labels
No labels