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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using bare Union as annotation is not handled properly #4638

Closed
KotlinIsland opened this issue Feb 4, 2023 · 1 comment
Closed

Using bare Union as annotation is not handled properly #4638

KotlinIsland opened this issue Feb 4, 2023 · 1 comment

Comments

@KotlinIsland
Copy link
Contributor

from typing import Union
def foo(a: Union): ...
Tc
    foo    1
馃憠 python -m robot.run test.robot
==============================================================================
Test                                                                          
==============================================================================
Tc                                                                    | FAIL |
AttributeError: __args__
------------------------------------------------------------------------------
@pekkaklarck
Copy link
Member

The reason for this issue is that when you have a: Union, our code recognizes it as union but unlike Union[...] the plain Union doesn't have __args__. That's easy to fix by changing union.__args__ to getattr(union, '__args__', ()) and after that the failure changes to same as if you use a: () (#4646). It's clearly not valid to have a union without any types and we could make it an explicit error. Alternatively we could just return the value as-is in this case, but I believe failure is better.

@pekkaklarck pekkaklarck changed the title (馃悶) Bare Union as an annotation causes a crash Using bare Union as annotation is not handled properly Feb 6, 2023
@pekkaklarck pekkaklarck changed the title Using bare Union as annotation is not handled properly (:lady_beetle:) Using bare Union as annotation is not handled properly Feb 6, 2023
pekkaklarck added a commit that referenced this issue Feb 28, 2023
In Python 3.6 bare Union has `__args__` but it's None which causes
problems. Our handy `has_args` utility handles such special cases.
yanne pushed a commit that referenced this issue Mar 18, 2023
It is now an explicit error to use `a: Union` or `a: ()`.
The error message also explains that an empty union isn't allowed.
Fixes #4638. Fixes #4646.
yanne pushed a commit that referenced this issue Mar 18, 2023
In Python 3.6 bare Union has `__args__` but it's None which causes
problems. Our handy `has_args` utility handles such special cases.
@pekkaklarck pekkaklarck changed the title (:lady_beetle:) Using bare Union as annotation is not handled properly Using bare Union as annotation is not handled properly Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants