pytos icon indicating copy to clipboard operation
pytos copied to clipboard

[Bug] Python 3.10.x not working

Open Cellebyte opened this issue 3 years ago • 3 comments

As of the new python release 3.10.x some modules which are used as a dependency are not working for pytos. It would be great if the dependencies can be updated to work also with python 3.10.

https://bugs.python.org/issue25988

$ python -m tufin.pytos.module
Traceback (most recent call last):
    from pytos.secureapp.helpers import Secure_App_Helper
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/pytos/secureapp/helpers.py", line 16, in <module>
    from pytos.securechange.helpers import Secure_Change_Helper
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/pytos/securechange/helpers.py", line 19, in <module>
    from pytos.common.helpers import Secure_API_Helper
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/pytos/common/helpers.py", line 7, in <module>
    from pytos.common import rest_requests
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/pytos/common/rest_requests.py", line 16, in <module>
    import requests_toolbelt
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/requests_toolbelt/__init__.py", line 12, in <module>
    from .adapters import SSLAdapter, SourceAddressAdapter
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/requests_toolbelt/adapters/__init__.py", line 12, in <module>
    from .ssl import SSLAdapter
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/requests_toolbelt/adapters/ssl.py", line 16, in <module>
    from .._compat import poolmanager
  File "/home/cellebyte/git/tools/cli/infoblox-sync/.venv/lib/python3.10/site-packages/requests_toolbelt/_compat.py", line 11, in <module>
    from collections import Mapping, MutableMapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)

Cellebyte avatar Feb 08 '22 08:02 Cellebyte

Workaround in pytos\common\rest_requests.py insert from collections import abc as collections instead of the top line

marioland avatar Mar 01 '22 07:03 marioland

@marioland the workaround only works when you manually patch the library. Would be better to fix it upstream.

Cellebyte avatar Mar 11 '22 12:03 Cellebyte

for the people waiting for #52 I have a working hotfix.

# <project_name>/_hotfix.py
from collections.abc import MutableMapping, Mapping
from collections import (
    ChainMap,
    namedtuple,
    OrderedDict,
    deque,
    defaultdict,
    Counter,
    UserDict,
    UserList,
    UserString,
)
from collections import abc

__all__ = [
    "ChainMap",
    "MutableMapping",
    "Mapping",
    "namedtuple",
    "OrderedDict",
    "abc",
    "deque",
    "defaultdict",
    "Counter",
    "UserDict",
    "UserList",
    "UserString",
]

# <project_name>.__init__.py
import sys
import <project_name>._hotfix as collections

sys.modules["collections"] = collections

Cellebyte avatar Nov 16 '22 18:11 Cellebyte