weave icon indicating copy to clipboard operation
weave copied to clipboard

Bug: TypeError('Type parameter ~R without a default follows type parameter with a default')

Open wochinge opened this issue 7 months ago • 0 comments

Hi there,

I ran into a weird import error when import weave via importlib.import_module:

We're using structured JSON logging, so please apologize the the format:

component: connectors.weave_connector
error: TypeError('Type parameter ~R without a default follows type parameter with a default')
package_name: my_package
event: Could not import component
level: error
timestamp: 2025-05-14T10:35:53.525103Z
exception:
  - exc_type: TypeError
    exc_value: Type parameter ~R without a default follows type parameter with a default
    exc_notes: []
    syntax_error: null
    is_cause: false
    frames:
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/my_package/importer.py
        lineno: 68
        name: _import_package
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/importlib/__init__.py
        lineno: 90
        name: import_module
      - filename: <frozen importlib._bootstrap>
        lineno: 1387
        name: _gcd_import
      - filename: <frozen importlib._bootstrap>
        lineno: 1360
        name: _find_and_load
      - filename: <frozen importlib._bootstrap>
        lineno: 1331
        name: _find_and_load_unlocked
      - filename: <frozen importlib._bootstrap>
        lineno: 935
        name: _load_unlocked
      - filename: <frozen importlib._bootstrap_external>
        lineno: 999
        name: exec_module
      - filename: <frozen importlib._bootstrap>
        lineno: 488
        name: _call_with_frames_removed
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/my_package/connectors/weave_connector.py
        lineno: 5
        name: <module>
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/weave/trace/autopatch.py
        lineno: 11
        name: <module>
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/weave/trace/weave_client.py
        lineno: 30
        name: <module>
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/weave/__init__.py
        lineno: 4
        name: <module>
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/weave/trace/api.py
        lineno: 11
        name: <module>
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/weave/type_handlers/__init__.py
        lineno: 1
        name: <module>
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/weave/type_handlers/Audio/audio.py
        lineno: 4
        name: <module>
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/weave/trace/serialization/custom_objs.py
        lineno: 7
        name: <module>
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/weave/trace/op.py
        lineno: 162
        name: <module>
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/typing.py
        lineno: 398
        name: inner
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/typing.py
        lineno: 1120
        name: _generic_class_getitem
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/typing.py
        lineno: 1275
        name: __init__
      - filename: /opt/hostedtoolcache/Python/3.12.8/x64/lib/python3.12/site-packages/pip/_vendor/typing_extensions.py
        lineno: 3517
        name: _collect_parameters

Unfortunately, I can't reproduce locally - only in our CI. However, I found the following issue online: https://github.com/pytorch/pytorch/issues/140914#issuecomment-2558677512

Based on that I believe the problem is that weave is mixing imports from typing and type_extensions here

So the solution would be to consolidate the imports.

wochinge avatar May 14 '25 12:05 wochinge