crossbario / crossbario/autobahn-python

TypeError: Subscripted generics cannot be used with class and instance checks

Open
#1,332 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-investigation wamp
Dominant language
Python
Stars
2.5k
Forks
768
PR merge metrics
No merged PRs in 30d

Description

Code:

    @wamp.register('network.xbr.console.find_markets', check_types=True)
    def find_markets(self,
                     created_from: Optional[int] = None,
                     limit: Optional[int] = None,
                     include_owners: Optional[List[bytes]] = None,
                     include_actors: Optional[List[bytes]] = None,
                     include_titles: Optional[List[str]] = None,
                     include_descriptions: Optional[List[str]] = None,
                     include_tags: Optional[List[str]] = None,
                     include_apis: Optional[List[bytes]] = None,
                     details: Optional[CallDetails] = None) -> List[bytes]:
        pass

Traceback:

2020-02-29T22:27:08+0100 [Router      26746] XbrNetworkApi.onUserError(): "TypeError: Subscripted generics cannot be used with class and instance checks"
Traceback (most recent call last):
  File "/home/oberstet/scm/crossbario/autobahn-python/autobahn/wamp/protocol.py", line 1020, in onMessage
    on_reply = txaio.as_future(endpoint.fn, *invoke_args, **invoke_kwargs)
  File "/home/oberstet/scm/crossbario/txaio/txaio/tx.py", line 365, in as_future
    return ensureDeferred(fun(*args, **kwargs))
  File "/home/oberstet/cpy381_5/lib/python3.8/site-packages/twisted/internet/defer.py", line 911, in ensureDeferred
    return _cancellableInlineCallbacks(coro)
  File "/home/oberstet/cpy381_5/lib/python3.8/site-packages/twisted/internet/defer.py", line 1529, in _cancellableInlineCallbacks
    _inlineCallbacks(None, g, status)
--- <exception caught here> ---
  File "/home/oberstet/cpy381_5/lib/python3.8/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
    result = g.send(result)
  File "/home/oberstet/scm/crossbario/autobahn-python/autobahn/wamp/protocol.py", line 506, in _type_check
    if not isinstance(arguments[name], kind.__args__):
  File "/home/oberstet/cpy381/lib/python3.8/typing.py", line 766, in __instancecheck__
    return self.__subclasscheck__(type(obj))
  File "/home/oberstet/cpy381/lib/python3.8/typing.py", line 774, in __subclasscheck__
    raise TypeError("Subscripted generics cannot be used with"
builtins.TypeError: Subscripted generics cannot be used with class and instance checks

https://github.com/crossbario/xbr-www/blob/ad2a7c0e5659d1af22d8232b5682d2557a7e32c4/backend/xbrnetwork/_api.py#L1095

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in autobahn/wamp/protocol.py at the _type_check call shown near line 506, then reproduce it with the check_types=True endpoint and annotations in xbrnetwork/_api.py near line 1095. Trace how Optional and List annotations are checked. Done means the endpoint no longer raises the reported TypeError while type checking its arguments.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.