Issue45776
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2021-11-10 06:54 by stcanny, last changed 2022-04-11 14:59 by admin.
Messages (7) | |||
---|---|---|---|
msg406074 - (view) | Author: Steve Canny (stcanny) | Date: 2021-11-10 06:54 | |
On CPython 3.10.0 on Windows but not MacOS, AttributeError is raised when referencing `abc` on collections (instead of importing `collections.abc`). >>> import collections >>> collections.abc.Container AttributeError: module 'collections' has no attribute 'abc' This works on MacOS CPython 3.10.0 and also works on Windows CPython 3.9.6. It's possibly interesting this coincides with collection ABCs being made unavailable directly from `collections` with this 3.9 -> 3.10 version change, but that's just a guess, for whatever it's worth. |
|||
msg406093 - (view) | Author: Steve Dower (steve.dower) * | Date: 2021-11-10 13:34 | |
Since collections.abc is a module, it should work if you import it: >>> import collections.abc >>> collections.abc.Container <class 'collections.abc.Container'> Submodules being implicitly imported is not part of any API guarantee, which will be why somebody changed it without considering this impact. |
|||
msg406103 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2021-11-10 14:49 | |
> this coincides with collection ABCs being made unavailable directly from `collections` with this 3.9 -> 3.10 version change Direct access from collections was removed after being deprecated for almost almost a decade ago: "Using or importing the ABCs from 'collections' instead " "of from 'collections.abc' is deprecated since Python 3.3, " "and in 3.10 it will stop working" So Windows is correctly reporting an AttributeError. The mystery is why it is still accessible on a Mac. That seems like a bug. |
|||
msg406105 - (view) | Author: Mark Dickinson (mark.dickinson) * | Date: 2021-11-10 15:53 | |
On Mac, collections.abc is imported at startup time via site.py (which imports rlcompleter, which imports inspect, which imports collections.abc). I'd guess it's the same on Linux. mdickinson@mirzakhani cpython % ./python.exe Python 3.11.0a2+ (heads/main:76d14fac72, Nov 10 2021, 15:43:54) [Clang 13.0.0 (clang-1300.0.29.3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys; "collections.abc" in sys.modules True >>> ^D mdickinson@mirzakhani cpython % ./python.exe -S Python 3.11.0a2+ (heads/main:76d14fac72, Nov 10 2021, 15:43:54) [Clang 13.0.0 (clang-1300.0.29.3)] on darwin >>> import sys; "collections.abc" in sys.modules False >>> ^D |
|||
msg406110 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2021-11-10 16:48 | |
> On Mac, collections.abc is imported at startup time > via site.py (which imports rlcompleter, which imports > inspect, which imports collections.abc). In inspect.py, the import of collections.abc is only used inside isawaitable(). We could make that a deferred import. |
|||
msg406113 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2021-11-10 16:56 | |
Also, the collections module could simply delete abc if it already exists due to collections.abc being imported first. |
|||
msg406119 - (view) | Author: Steve Canny (stcanny) | Date: 2021-11-10 17:46 | |
The resolution for me (the python-pptx and python-docx libraries) is clear, to add a separate `import collections.abc` statement rather than assuming (hoping) that the `collections.abc` module is available on an `abc` attribute of the `collections` module. I chalk that up to a gap in my knowledge of the guarantees provided by module imports and falling into trusting my method just because it worked :) But I will argue for maintenance of backward compatibility here, just for the sake of those unable or unwilling to modify existing code. 1. Removing the availability of e.g. `Container` directly from `collections` is not the same as removing the availability of `abc` from collections. The deprecation warning we have all seen many times admits both interpretations. So I would argue we have at least not _explicitly_ stated that `import collections; collections.abc` would stop working. 2. `import collections; collections.abc` worked in Windows Python 3.9.6. As such, it was part of the de-facto spec. When we publish a behavior, a certain number of folks will come to depend on it, whether it is stated or not. So there will be breakage here. It's not my place to judge whether the breakage or restoration of the behavior is the greater value; my claim is only that there will be breakage cost. That would include the time to deal with additional issue reports from folks who don't find this issue before reporting. So I've said my piece on this. I'm grateful for your attention to this conversation and will cheerfully accept whatever resolution you decide on. Thanks to all of you for participating in this great project that empowers so many; I'm very proud to be a small part of it :) |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:59:52 | admin | set | github: 89934 |
2021-11-10 17:46:37 | stcanny | set | messages: + msg406119 |
2021-11-10 16:56:54 | rhettinger | set | messages: + msg406113 |
2021-11-10 16:48:31 | rhettinger | set | messages: + msg406110 |
2021-11-10 15:53:21 | mark.dickinson | set | nosy:
+ mark.dickinson messages: + msg406105 |
2021-11-10 14:49:02 | rhettinger | set | nosy:
+ rhettinger messages: + msg406103 |
2021-11-10 13:34:50 | steve.dower | set | messages: + msg406093 |
2021-11-10 06:54:36 | stcanny | create |