Skip to content

py3: import certain things from collections.abc #28012

@slel

Description

@slel

Background (read
Python 3 documentation for the collections module
for more detail):

  • Collections Abstract Base Classes
    ("CABCs") moved to the collections.abc module in Python 3.3.

  • These "Collections Abstract Base Classes" are: AsyncGenerator,
    AsyncIterable, AsyncIterator, Awaitable, Bytestring,
    Callable, Collection, Container, Coroutine, Generator,
    Hashable, ItemsView, Iterable, Iterator, KeysView,
    Mapping, MappingView, MutableMapping, MutableSequence,
    MutableSet, Reversible, Sequence, Set, Sized, ValuesView.

  • For backwards compatibility, CABCs continue to be visible
    in the collections module through Python 3.8; and can be
    imported either from collections or from collections.abc.

  • Starting with Python 3.9, CABCs must be imported from collections.abc.

  • In Python 2 they could only be imported from 'collections',
    not from 'collections.abc'. So while Sage was keeping
    Py2 and Py3 compatible it made sense to import from collections.

  • In Python 3.7 and Python 3.8, importing them from collections
    gives a deprecation warning. This warning was silenced in Sage,
    see py3: last test in tests/cmdline.py #28002.

In this ticket we import the classes from collections.abc.

We do not suppress the silencing of the deprecation warning yet.
See comment:23 and #30768.

CC: @fchapoton @jhpalmieri @slel @videlec @tscrim

Component: python3

Keywords: days101, collections.abc

Author: Samuel Lelièvre

Branch: 4f80136

Reviewer: John Palmieri

Issue created by migration from https://trac.sagemath.org/ticket/28012

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions