Skip to content

Unittest failing with “ AttributeError: module 'typing' has no attribute 'StatusLike' ” #1496

@mxjeff

Description

@mxjeff

Trying to run unittest against 13.0.1 I got an AttributeError.

I first stumble upon the issue trying to update the Debian package (python 3.12 in a chroot), but I reproduced with python 3.11 as well.

Here is what I got running python -m unittest discover (inside 13.0.1 extracted tar ball):

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/lib/python3.11/unittest/__main__.py", line 18, in <module>
    main(module=None)
  File "/usr/lib/python3.11/unittest/main.py", line 101, in __init__
    self.parseArgs(argv)
  File "/usr/lib/python3.11/unittest/main.py", line 127, in parseArgs
    self._do_discovery(argv[2:])
  File "/usr/lib/python3.11/unittest/main.py", line 247, in _do_discovery
    self.createTests(from_discovery=True, Loader=Loader)
  File "/usr/lib/python3.11/unittest/main.py", line 157, in createTests
    self.test = loader.discover(self.start, self.pattern, self.top)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/unittest/loader.py", line 322, in discover
    tests = list(self._find_tests(start_dir, pattern))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/unittest/loader.py", line 377, in _find_tests
    tests, should_recurse = self._find_test_path(full_path, pattern)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/unittest/loader.py", line 453, in _find_test_path
    tests = self.loadTestsFromModule(package, pattern=pattern)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/unittest/loader.py", line 122, in loadTestsFromModule
    obj = getattr(module, name)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/dev/shm/websockets/websockets/imports.py", line 77, in __getattr__
    return import_name(name, source, namespace)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/dev/shm/websockets/websockets/imports.py", line 28, in import_name
    return getattr(module, name)
           ^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'typing' has no attribute 'StatusLike'

Not sure I understand what is going on here, is there a typo in lazy importing?

diff --git a/src/websockets/__init__.py b/src/websockets/__init__.py
index ac02a9f..7bd35cf 100644
--- a/src/websockets/__init__.py
+++ b/src/websockets/__init__.py
@@ -183,7 +183,7 @@ else:
             "ExtensionParameter": ".typing",
             "LoggerLike": ".typing",
             "Origin": ".typing",
-            "StatusLike": "typing",
+            "StatusLike": ".typing",
             "Subprotocol": ".typing",
         },
         deprecated_aliases={

The above patch is solving the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions