Home > Enterprise >  Python 3.10 Iterables Attribute change from 3.8?
Python 3.10 Iterables Attribute change from 3.8?

Time:12-11

I get this error in Python3.10.6

    isinstance(pattern, collections.Iterable):
AttributeError: module 'collections' has no attribute 'Iterable'

in a significant and critical legacy program I didn't write (it's the buildsystem for another product). It worked fine with 3.8.10. The error is breaking the build on GitHub CI under Linux. Seems like they upgraded Python a couple of days ago. Does anyone have a suggestion to fix it?

CodePudding user response:

I tried following code in python3.10 and python3.8 and it seems to work on both:

try:
    # python 3.10
    from collections.abc import Iterable
except ImportError:
    # if failed, fall back to python 3.8
    from collections import Iterable


pattern = [1, 2, 3]

print(isinstance(pattern, Iterable))

results :

True

CodePudding user response:

collections.abc.Iterable works on both 3.8 and 3.10

  • Related