druid-io / pydruid

A Python connector for Druid
Other
506 stars 194 forks source link

fix: compatible with python3.8 #234

Closed aisk closed 3 years ago

aisk commented 3 years ago

Since abc is a submodule in collections and not imported to collections, directly using collections.abc.MutableSequence will cause error in newer versions (I tested it on 3.8.5, but I think 3.7 may have the same issue):

>>> import collections
>>> collections.abc.MutableSequence
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/anlong/.homebrew/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/collections/__init__.py", line 55, in __getattr__
    raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
AttributeError: module 'collections' has no attribute 'abc'

And the current code will cause this error: python -c "from pydruid import client".

I think this issue was not found because if we run import collections.abc or from collections.abc import x before, the collections.abc will be added to collections. And many thrid party have codes like this.

But anyway, I think we should fix this.

aisk commented 3 years ago

I think pytest may hide this issue so we don't found it: https://stackoverflow.com/questions/52798967/why-can-i-access-collections-abc-in-tests-but-not-in-production .

lokkju commented 3 years ago

Bumping, this is a PITA right now

lokkju commented 3 years ago

Also, this was previously discussed in https://github.com/druid-io/pydruid/issues/169 but wasn't correctly resolved.