[issue35806] typing module adds objects to sys.modules that don't look like modules

2019-01-28 Thread Guido van Rossum
Guido van Rossum added the comment: Thanks! -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.

[issue35806] typing module adds objects to sys.modules that don't look like modules

2019-01-27 Thread Nick Coghlan
Nick Coghlan added the comment: OK, I've filed #35839 to propose falling back to a regular search when the __spec__ attribute is missing, while treating "obj.__spec__ is None" as a true negative cache entry. -- ___ Python tracker

[issue35806] typing module adds objects to sys.modules that don't look like modules

2019-01-27 Thread Ronald Oussoren
Ronald Oussoren added the comment: Note that I will have to special case namespaces like typing.re anyway in my code, being a namespace that does not correspond to a "real" module whose code I can analyse. #35791 was mostly about 3th-party code like apipkg that are "real" modules, but for s

[issue35806] typing module adds objects to sys.modules that don't look like modules

2019-01-27 Thread Guido van Rossum
Guido van Rossum added the comment: Option 2 sounds best. I am also not against adding __spec__ but I think we should support the idiom regardless, and I don’t consider this a bug in the typing module — at best there’s a slight improvement. On Sun, Jan 27, 2019 at 6:50 AM Nick Coghlan wrote:

[issue35806] typing module adds objects to sys.modules that don't look like modules

2019-01-27 Thread Nick Coghlan
Nick Coghlan added the comment: Closing this without any changes contradicts the answer we gave Ronald on #35791 that it's expected behaviour for importlib.find_spec() to throw an exception for already loaded modules without a __spec__ attribute. So if this stays closed, then we should reope

[issue35806] typing module adds objects to sys.modules that don't look like modules

2019-01-22 Thread Guido van Rossum
Guido van Rossum added the comment: OK, I don't see a bug here. The docs for sys.modules are pretty vague -- I don't believe they imply that all values in sys.modules must have every attribute of a Module object. -- resolution: -> wont fix stage: test needed -> resolved status: open

[issue35806] typing module adds objects to sys.modules that don't look like modules

2019-01-22 Thread Ronald Oussoren
Ronald Oussoren added the comment: In response to my previous message: "Messing" with sys.modules appears to be good enough work around for me, at least in the limited testing I've done so far. The new version of modulegraph hasn't seen any testing beyond a largish set of unit tests though.

[issue35806] typing module adds objects to sys.modules that don't look like modules

2019-01-22 Thread Ronald Oussoren
Ronald Oussoren added the comment: The reason I filed #35791 is that I'm rewriting modulegraph[1] using importlib and run into some problems due to importlib.util.find_spec() failing for names that are already imported. Working around that in general probably will require reimplementing bit

[issue35806] typing module adds objects to sys.modules that don't look like modules

2019-01-22 Thread Guido van Rossum
Guido van Rossum added the comment: It's been a somewhat well-known idiom for modules to replace themselves in sys.modules with an object that implements some special behaviors (e.g. dynamic loading). This "just works" and AFAIK people have been doing this for ages. Typically such classes ju

[issue35806] typing module adds objects to sys.modules that don't look like modules

2019-01-22 Thread Eric Snow
New submission from Eric Snow : tl;dr Should all objects in sys.modules look like module objects? In #35791 Ronald described a problem with a "module" added to sys.modules that does not have all the attributes a module should have. He also mentioned a similar problem with typing.io [1]: