Skip to content
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

collections: remove deprecated aliases to ABC classes #81505

Closed
vstinner opened this issue Jun 17, 2019 · 16 comments
Closed

collections: remove deprecated aliases to ABC classes #81505

vstinner opened this issue Jun 17, 2019 · 16 comments
Labels
3.9 only security fixes stdlib Python modules in the Lib dir

Comments

@vstinner
Copy link
Member

BPO 37324
Nosy @vstinner, @serhiy-storchaka, @yan12125, @hugovk, @tirkarthi
PRs
  • bpo-37324: Remove ABC aliases from collections #14171
  • bpo-37324: Remove ABC aliases from collections #23754
  • Superseder
  • bpo-25988: collections.abc.Indexable
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-10-07.13:20:44.080>
    created_at = <Date 2019-06-17.20:38:32.149>
    labels = ['library', '3.9']
    title = 'collections: remove deprecated aliases to ABC classes'
    updated_at = <Date 2021-01-12.23:16:45.583>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2021-01-12.23:16:45.583>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-10-07.13:20:44.080>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2019-06-17.20:38:32.149>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37324
    keywords = ['patch']
    message_count = 8.0
    messages = ['345905', '345906', '345908', '345923', '348011', '348424', '354092', '384981']
    nosy_count = 5.0
    nosy_names = ['vstinner', 'serhiy.storchaka', 'yan12125', 'hugovk', 'xtreak']
    pr_nums = ['14171', '23754']
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '25988'
    type = None
    url = 'https://bugs.python.org/issue37324'
    versions = ['Python 3.9']

    @vstinner
    Copy link
    Member Author

    Extract of collections documentation:
    https://docs.python.org/dev/library/collections.html

    "Deprecated since version 3.3, will be removed in version 3.9: Moved Collections Abstract Base Classes to the collections.abc module. For backwards compatibility, they continue to be visible in this module through Python 3.8."

    Attached PR removes these aliases.

    @vstinner vstinner added 3.9 only security fixes stdlib Python modules in the Lib dir labels Jun 17, 2019
    @vstinner
    Copy link
    Member Author

    pip is broken by this change, causing test_venv to fail: html5lib still uses collections to get ABC.

    FAIL: test_with_pip (test.test_venv.EnsurePipTest)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/home/vstinner/prog/python/master/Lib/test/test_venv.py", line 407, in do_test_with_pip
        self.run_with_capture(venv.create, self.env_dir,
      File "/home/vstinner/prog/python/master/Lib/test/test_venv.py", line 69, in run_with_capture
        func(*args, **kwargs)
    subprocess.CalledProcessError: Command '['/tmp/tmpkxga42lx/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/vstinner/prog/python/master/Lib/test/test_venv.py", line 466, in test_with_pip
        self.do_test_with_pip(False)
      File "/home/vstinner/prog/python/master/Lib/test/test_venv.py", line 415, in do_test_with_pip
        self.fail(msg.format(exc, details))
    AssertionError: Command '['/tmp/tmpkxga42lx/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
    
    **Subprocess Output**
    /tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_vendor/pyparsing.py:3068: SyntaxWarning: invalid escape sequence \w
    /tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_vendor/pyparsing.py:3068: SyntaxWarning: invalid escape sequence \w
    Traceback (most recent call last):
      File "/home/vstinner/prog/python/master/Lib/runpy.py", line 192, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/home/vstinner/prog/python/master/Lib/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "/home/vstinner/prog/python/master/Lib/ensurepip/__main__.py", line 5, in <module>
        sys.exit(ensurepip._main())
      File "/home/vstinner/prog/python/master/Lib/ensurepip/__init__.py", line 198, in _main
        return _bootstrap(
      File "/home/vstinner/prog/python/master/Lib/ensurepip/__init__.py", line 117, in _bootstrap
        return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
      File "/home/vstinner/prog/python/master/Lib/ensurepip/__init__.py", line 27, in _run_pip
        import pip._internal
      File "<frozen zipimport>", line 259, in load_module
      File "/tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/__init__.py", line 40, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py", line 8, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py", line 12, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/__init__.py", line 6, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/completion.py", line 6, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/base_command.py", line 25, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/index.py", line 14, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_vendor/html5lib/__init__.py", line 25, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_vendor/html5lib/html5parser.py", line 8, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_vendor/html5lib/_tokenizer.py", line 16, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_vendor/html5lib/_trie/__init__.py", line 3, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_vendor/html5lib/_trie/py.py", line 6, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/tmp/tmpwhk_ss_e/pip-19.0.3-py2.py3-none-any.whl/pip/_vendor/html5lib/_trie/_base.py", line 3, in <module>
    ImportError: cannot import name 'Mapping' from 'collections' (/home/vstinner/prog/python/master/Lib/collections/__init__.py)

    @vstinner
    Copy link
    Member Author

    html5lib has already been fixed:
    https://github.com/vstinner/html5lib-python/commit/4f9235752cea29c5a31721440578b430823a1e69

    But latest html5lib release was version 1.0.1 at... Dec 7, 2017 :-(

    Paul Ganssle requested a new html5lib release... to fix the collections warning :-)
    html5lib/html5lib-python#419

    @vstinner
    Copy link
    Member Author

    Oh. I wasn't aware of the previous attempt: #10596 there is a long discussion there. The blocker issue was also html5lib.

    @vstinner
    Copy link
    Member Author

    Right now (pip 19.1.1?), "./python -m venv env" still fails because of html5lib/_trie/py.py. There is still no activitiy on the request to get a new release:
    html5lib/html5lib-python#419

    @yan12125
    Copy link
    Mannequin

    yan12125 mannequin commented Jul 25, 2019

    In CPython commit 5380def, bundled pip is updated to 19.2.1, and since pip 19.2 an html5lib patch is backported [1] to "prefer importing from collections.abc instead of collections" [2]. I believe #10596 can be revisited now.

    [1] pypa/pip@ef7ca14
    [2] pypa/pip@3d6bb3a

    @tirkarthi
    Copy link
    Member

    I think this can be closed since https://bugs.python.org/issue25988 has the PR merged.

    @vstinner
    Copy link
    Member Author

    New changeset c47c78b by Hugo van Kemenade in branch 'master':
    bpo-37324: Remove ABC aliases from collections (GH-23754)
    c47c78b

    @vivainio
    Copy link

    This broke setuptools 38.5.2

    @hugovk
    Copy link
    Member

    hugovk commented Nov 10, 2022

    setuptools 38.5.2 was released in 2018.

    Python 3.10 was released on 2021-10-04, when setuptools was at 58.2.0, and is now at 65.5.1.

    I recommend upgrading.

    @vivainio
    Copy link

    @hugovk I was pinned to old version because newer setuptools created metadata that was incompatible with old version of Artifactory

    @vstinner
    Copy link
    Member Author

    Well, if you start to pin versions, you should also pin the Python version: use Python 3.9 or older, which still provide deprecated aliases to collections ABC.

    @vivainio
    Copy link

    @vstinner that's what we are doing, but we are now evaluating updating to python 3.10 and this (soft) blocker came up

    @vivainio
    Copy link

    For posteriority, I packaged up the compatibility shims to a python package in pypi: https://github.com/vivainio/fix-py-collections

    @vstinner
    Copy link
    Member Author

    For posteriority, I packaged up the compatibility shims to a python package in pypi: https://github.com/vivainio/fix-py-collections

    I proposed https://peps.python.org/pep-0606/ but it got rejected.

    @vivainio
    Copy link

    vivainio commented Nov 14, 2022

    I proposed https://peps.python.org/pep-0606/ but it got rejected.

    If there are a lot of breaking changes like this, maybe they could be addressed with a single "compat" package like six. I don't mind if it's a third party package, really.

    Edit: I changed my mind. Third party package works very badly with setuptools, as you would need it available before running setup.py. This should come with Python

    rseragon added a commit to rseragon/ChemDataExtractor that referenced this issue Jul 27, 2023
    Imports like Sequence, MutableSequence, etc. are deprecated since
    python3.3 and are removed from 3.8. This commit fixes these import
    problems for users with 3.8+
    ref: python/cpython#81505
    augusto added a commit to augusto/samplemod that referenced this issue Sep 18, 2023
    Replace nose with pytest as nose is incompatible with the collections chances on python 3.10 - python/cpython#81505
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants