fix(test): replace collections.Callable, removed in Python 3.10 - #347
Merged
Conversation
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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Problem
tests/test_unit/test_core/test_client.py::test_client_try_importuses:collections.Callablehas been an alias forcollections.abc.Callablesince Python 3.3 and was removed in 3.10, so the test raises:The suite therefore only passes on Python ≤ 3.9.
Why it went unnoticed
.travis.ymltests 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-unusedcollectionsimport go, rather than keeping an import around for a single predicate.Verified
Python 3.11.9,
make test-cov:make lint(flake8) andpython -m compileall ucloudboth stay at exit 0.