You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Getting type hints in Field.__set_name__ can cause RuntimeError #73
from __future__ import annotations
from pyfields import field
class Foo:
bar: Foo = field()
I got RuntimeError: Error calling __set_name__ on 'NativeField' instance 'bar' in 'Foo'. It is because class Foo does not exist yet and field calls typing.get_type_hints at line 299.
changed the title [-]Getting type hints in Field.__set_name__ can cause RuntimeError[/-][+]Getting type hints in `Field.__set_name__` can cause `RuntimeError`[/+]on Sep 17, 2020
So after investigating a bit: from __future__ import annotations is a special line introduced in PEP563 in order to enable python 3.10 behaviour in earlier versions. However this behaviour becomes similar to what happens when you use string type hints. So I am able to reproduce the issue without the PEP563:
frompyfieldsimportfieldclassFoo:
bar: 'Foo'=field()
I will fix this by enabling delayed type hint resolution.
Fixed in 1.3.0 (as well as field access from class #12, which was waiting a fix on pycharm side that is now available - I had to make the patch for them :) )
Activity
[-]Getting type hints in Field.__set_name__ can cause RuntimeError[/-][+]Getting type hints in `Field.__set_name__` can cause `RuntimeError`[/+]smarie commentedon Sep 18, 2020
Thanks @micuda for reporting this issue ! I'll have a look asap
smarie commentedon Sep 21, 2020
So after investigating a bit:
from __future__ import annotationsis a special line introduced in PEP563 in order to enable python 3.10 behaviour in earlier versions. However this behaviour becomes similar to what happens when you use string type hints. So I am able to reproduce the issue without the PEP563:I will fix this by enabling delayed type hint resolution.
smarie commentedon Sep 21, 2020
Fixed in 1.3.0 (as well as field access from class #12, which was waiting a fix on pycharm side that is now available - I had to make the patch for them :) )