Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type check improve #1405

Merged
merged 2 commits into from Jul 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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