Skip to content

Deprecation warning when importing on Python 3.10 #104

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

Closed
domdfcoding opened this issue Dec 15, 2020 · 1 comment · Fixed by #105
Closed

Deprecation warning when importing on Python 3.10 #104

domdfcoding opened this issue Dec 15, 2020 · 1 comment · Fixed by #105

Comments

@domdfcoding
Copy link
Contributor

On Python 3.10.0a3:

Python 3.10.0a3 (default, Dec  8 2020, 03:28:14) 
>>> import tabulate
/tmp/tabulate-venv/lib/python3.10/site-packages/tabulate.py:16: DeprecationWarning: 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
  from collections import Iterable
>>> 

This was "fixed" in 3bfe294, and indeed there's no warning on 3.8.5:

Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
>>> import tabulate
>>> 

The relevant code is

if python_version_tuple() >= ("3", "3", "0"):
from collections.abc import Iterable
else:
from collections import Iterable

However, the fix is not tolerant to Python 3.10's extra digit -- python_version_tuple() returns ('3', '10', '0a3'), and since these are strings '10' is treated as being less than '3'. The recommended way to perform this is:

if sys.version_info >= (3, 3):
    from collections.abc import Iterable
else:
    from collections import Iterable

since sys.version_info is a tuple of ints, and correctly handles two-digit minor versions.

Happy to submit a PR to fix this, assuming you still want to support Python versions that old?

@hroncok
Copy link

hroncok commented Feb 8, 2021

This is now a hard ImportError since 3.10.0a5:

ERROR: Failure: ImportError (cannot import name 'Iterable' from 'collections' (/usr/lib64/python3.10/collections/__init__.py))
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/usr/lib/python3.10/site-packages/nose/loader.py", line 416, in loadTestsFromName
    module = self.importer.importFromPath(
  File "/usr/lib/python3.10/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python3.10/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib64/python3.10/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "/usr/lib64/python3.10/imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 729, in _load
  File "<frozen importlib._bootstrap>", line 698, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 833, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/builddir/build/BUILD/tabulate-0.8.7/test/test_regression.py", line 7, in <module>
    from tabulate import tabulate, _text_type, _long_type, TableFormat, Line, DataRow
  File "/builddir/build/BUILD/tabulate-0.8.7/tabulate.py", line 16, in <module>
    from collections import Iterable
ImportError: cannot import name 'Iterable' from 'collections' (/usr/lib64/python3.10/collections/__init__.py)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants