robotframework / PythonLibCore

Tools to ease creating larger test libraries for Robot Framework using Python
Apache License 2.0
64 stars 23 forks source link

Support Python 3.10 and ensure that new type hints works #87

Closed aaltat closed 3 years ago

aaltat commented 3 years ago

3.10 brings new way to present type hints. Make sure that example this works:

def func(arg: list[int] | list[str]):
    ...
pekkaklarck commented 3 years ago

Doesn't PLC just forward __annotations__ to RF? If yes, this ought to work with RF 4.1.1 and newer out of the box. Adding explicit tests is definitely a good idea anyway.

aaltat commented 3 years ago

Yes, it does forwards. If there is no changes in that area, things will most likely just work. But testing it out, is always a good idea.

pekkaklarck commented 3 years ago

PLC could actually convert x | y into (x, y) that RF handles as well. The benefit would be that then using x | y syntax would work also with older RF versions. I doubt that's worth the effort, though. People using Python 3.10 are likely to use latest RF version as well.

aaltat commented 3 years ago

I need to check, I think that is tested in unit level, but I used the Py3.10 in acceptance tests.

pekkaklarck commented 3 years ago

The x | y syntax requires Python 3.10 so no point testing with older. But it also requires RF 4.1.1 because x | y is actually types.UnionType and earlier RF versions don't support that. If PLC would convert types.UnionType to a tuple (just accessing its __args__ is enough), it would work also with earlier RF 4 versions. Implementation would be something like

try:
    from types import UnionType
except ImportError:
    UnionType = ()

...

if isintance(typ, UnionType):
    typ = typ.__args__
aaltat commented 3 years ago

PLC might actually do it already. Just need test and check how it goes in the code.