Skip to content
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

Python: Iterable moved from collections to collections.abc #430

Open
eLvErDe opened this issue Oct 31, 2024 · 1 comment
Open

Python: Iterable moved from collections to collections.abc #430

eLvErDe opened this issue Oct 31, 2024 · 1 comment

Comments

@eLvErDe
Copy link
Contributor

eLvErDe commented Oct 31, 2024

Hello,

On recent Python version (worked with 3.9, fails with 3.11), Python script crash because Iterable import namespace has changed.

The following patch fixes it:

--- a/harisekhon/utils.py
+++ b/harisekhon/utils.py
@@ -54,6 +54,10 @@ import defusedxml.ElementTree as ET
 #     pass
 # Python 2.6 throws ExpatError instead of ParseError
 # from xml.parsers.expat import ExpatError
+try:
+    from collections import Iterable
+except ImportError:  # Recent Python like 3.11
+    from collections.abc import Iterable
 
 __author__ = 'Hari Sekhon'
 __version__ = '0.14.0'
@@ -1105,12 +1109,12 @@ def isIP(arg):
 
 def isIterable(arg):
     # collections.Iterable Python 2.6+
-    return isinstance(arg, collections.Iterable)
+    return isinstance(arg, Iterable)
 
 
 def isIterableNotStr(arg):
     # collections.Iterable Python 2.6+
-    return isinstance(arg, collections.Iterable) and not isStr(arg)
+    return isinstance(arg, Iterable) and not isStr(arg)
 
 
 def isJavaException(arg):
@HariSekhon
Copy link
Owner

Thanks for raising this.

If you want to raise it as a pull request to the

https://github.com/HariSekhon/pylib

repo then I'll approve it and you'll get contribution credit.

If you don't want to then I'll make the change.

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

No branches or pull requests

2 participants