Skip to content

Elegant typehints cannot resolve forward-references #14

@ded8393

Description

@ded8393

Fails to resolve forward-references.

from dataclasses import dataclass
from typing import TypeVar, TYPE_CHECKING, Generic

@dataclass
class A: 
   b: 'B'  # NameError: 'B' is not defined

@dataclass
class B:
    a: A

Does not resolve even under conditions where the following are added to the top (forward-references should generally resolve via quotations, however PEP563 gives these suggestions

T = TypeVar('T')
if typing.TYPE_CHECKING:
    B = Generic[T]

from future import __annotations__

sphinx-autodoc-typehints uses parameter set_type_checking_flag in conf.py. Setting this does not affect elegant_typehints.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions