Skip to content

Commit

Permalink
Type check improve (#1405)
Browse files Browse the repository at this point in the history
* fix 1322

* better wording
  • Loading branch information
om26er committed Jul 20, 2020
1 parent 2774823 commit 7671a99
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions autobahn/wamp/protocol.py
Expand Up @@ -502,13 +502,17 @@ async def _type_check(*args, **kwargs):
response = []
for name, kind in func.__annotations__.items():
if name in arguments:
# if a "type" has __origin__ attribute it is a
# parameterized generic
if getattr(kind, "__origin__", None) == Union:
expected_types = [arg.__name__ for arg in kind.__args__]
if not isinstance(arguments[name], kind.__args__):
response.append(
"'{}' required={} got={}".format(name, kind.__name__, type(arguments[name]).__name__))
"'{}' expected types={} got={}".format(name, expected_types,
type(arguments[name]).__name__))
elif not isinstance(arguments[name], kind):
response.append(
"'{}' required={} got={}".format(name, kind.__name__, type(arguments[name]).__name__))
"'{}' expected type={} got={}".format(name, kind.__name__, type(arguments[name]).__name__))
if response:
raise TypeCheckError(', '.join(response))
return await txaio.as_future(func, *args, **kwargs)
Expand Down

0 comments on commit 7671a99

Please sign in to comment.