-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Cannot use keyword with parameterized special form like TypeForm[param]
as type hint
#5393
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
Comments
Hi, I tried it myself and it doesn't seems like an error due to RF. It looks like you're using According to the error message, I fixed it with this approach: from robot.api.deco import keyword
from typing import TypeVar
T = TypeVar('T', bound=object)
@keyword
def foo(a: T):
print(a) Robotframework file is the same. With this approach i get no errors. |
i think you're getting from typing_extensions import TypeForm
def validate_type(value: object, t: TypeForm[object]):
... # do some runtime type check
validate_type(1, int | str) see https://peps.python.org/pep-0747/ for more info |
I can reproduce the problem. It's due to our type hint inspecting code considering that nothing that's not an instance of Luckily this problem doesn't cause the whole execution to crash, but not being able to use a keyword with such a type hint is obviously annoying as well. This certainly needs to be fixed and luckily the fix seem to be rather simple. There will be no conversion for |
typing_extensions.TypeForm
annotationTypeForm[param]
as type hint
sounds good, like i said a converter isn't really necessary because a string is already a valid
so that should make it trivial to support it in robotframework. though i guess it could be enhanced further to validate that the string is actually a valid type, but i'm happy to just have the fix for the crash, because i don't use |
Converting string |
|
This is related to #5393. Problems were discovered when unit tests didn't succeed on Python 3.8. Investigation reveladed this: 1. Python 3.8 doesn't have Annotated that was used in a test that validated the fix for #5393. 2. Annotated can be imported from typing_extensions in tests, but it turned out that Python 3.8 get_origin and get_args don't handle it properly so test continued to fail. 3. A fix for the above was trying to import also get_origin and get_args from typing_extensions on Python 3.8. That fixed the provious problem, but string representation was still off. 4. It turned out that our type_name and type_repr didn't handle Annotated and TypeRef properly. Most likely the same issue occurred also with other parameterized special forms.
TypeForm
is an experimental new type for typing type anotations, see https://peps.python.org/pep-0747/. it was added totyping_extensions
in version 4.13.0.attempting to use it in a keyword causes robot to crash:
note that no conversions are required to convert an argument to a
TypeForm
, because it's valid for type annotations to be strings:The text was updated successfully, but these errors were encountered: