Skip to content

Getting type hints in Field.__set_name__ can cause RuntimeError #73

@micuda

Description

@micuda

Hi,
at first, thank You for the great library. =)

For code

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.

def __set_name__(self,
owner, # type: Type[Any]
name # type: str
):
if owner is not None:
# fill all the information about how it is attached to the class
cls_type_hints = get_type_hints(owner)
self.set_as_cls_member(owner, name, owner_cls_type_hints=cls_type_hints)

For now I just don't annotate attributes like this, but it is weird (and inconsistent) that some attributes have typing annotation and some don't. =)

I'm not sure where and how to fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions