Skip to content

fix(test): replace collections.Callable, removed in Python 3.10 - #347

Merged
Episkey-G merged 1 commit into
masterfrom
fix/collections-callable-py310
Aug 18, 2026
Merged

fix(test): replace collections.Callable, removed in Python 3.10#347
Episkey-G merged 1 commit into
masterfrom
fix/collections-callable-py310

Conversation

@Episkey-G

Copy link
Copy Markdown
Collaborator

Problem

tests/test_unit/test_core/test_client.py::test_client_try_import uses:

if isinstance(client_factory, collections.Callable):

collections.Callable has been an alias for collections.abc.Callable since Python 3.3 and was removed in 3.10, so the test raises:

E   AttributeError: module 'collections' has no attribute 'Callable'
tests/test_unit/test_core/test_client.py:105: AttributeError

The suite therefore only passes on Python ≤ 3.9.

Why it went unnoticed

.travis.yml tests 3.5 / 3.6 / 3.7 — all below the cutoff. And Travis has not run on this repo for a long time, so nothing has exercised the suite on a modern interpreter.

Fix

Use the builtin callable().

Same semantics — collections.abc.Callable.__subclasshook__ just checks for __call__ — and it lets the now-unused collections import go, rather than keeping an import around for a single predicate.

-import collections
...
-        if isinstance(client_factory, collections.Callable):
+        if callable(client_factory):

Verified

Python 3.11.9, make test-cov:

result
before 1 failed, 47 passed, 37 skipped
after 48 passed, 37 skipped

make lint (flake8) and python -m compileall ucloud both stay at exit 0.

test_client_try_import used `isinstance(x, collections.Callable)`.
`collections.Callable` has been an alias for `collections.abc.Callable`
since 3.3 and was removed in 3.10, so the test raises:

    AttributeError: module 'collections' has no attribute 'Callable'

The suite therefore only passes on Python <= 3.9. .travis.yml tests
3.5/3.6/3.7, which is why this was never noticed -- and Travis has not
run on this repo for a long time either.

Uses the builtin `callable()` instead of `collections.abc.Callable`:
same semantics (collections.abc.Callable.__subclasshook__ just checks
for __call__), and it drops the now-unused `collections` import rather
than keeping one around for a single predicate.

Verified on Python 3.11.9:
    before   1 failed, 47 passed, 37 skipped
    after    48 passed, 37 skipped
@sonarqubecloud

Copy link
Copy Markdown

@Episkey-G
Episkey-G merged commit b4bcbb0 into master Aug 18, 2026
1 check passed
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 this pull request may close these issues.

1 participant