This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author antonagestam
Recipients Guido.van.Rossum, The Compiler, antonagestam, eric.smith, gvanrossum, kj, larry, levkivskyi
Date 2022-03-20.18:42:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1647801751.14.0.390616200539.issue43463@roundup.psfhosted.org>
In-reply-to
Content
As a consumer of `get_type_hints()` I think it'd be valuable to even have partially resolved types. My use case is that I provide an `Annotated` alias with a marker, and all I care about when inspecting user type hints is whether or not the arguments of an `Annotated` type contains my marker object. So ideally the fallback to an unresolved string or a sentinel object such as the proposed `typing.Unresolvable` should happen at the "lowest resolvable level" so that what can be resolved isn't lost.


By example, I'm saying that I think that this code:

    marker = object()

    def dec(cls):
        print(get_type_hints(cls))
        return cls

    @dec
    class A(abc.ABC):
        forward: Annotated[B, marker]

    class B:
        ...

Should produce:

    {"forward": Annotated[Unresolvable["B"], marker]}

I guess this would apply in situations where for instance a part of a union isn't resolvable too. If we have a union A|B where A is resolvable and B isn't, it should be resolved to:

    A | Unresolvable["B"]

And not to:

    Unresolvable["A | B"]

(I think for this perspective it's irrelevant whether unresolved types have a sentinel type or are just represented as strings).

(Here's the library that's my use case for the curious: https://github.com/antonagestam/abcattrs)
History
Date User Action Args
2022-03-20 18:42:31antonagestamsetrecipients: + antonagestam, gvanrossum, larry, eric.smith, Guido.van.Rossum, The Compiler, levkivskyi, kj
2022-03-20 18:42:31antonagestamsetmessageid: <1647801751.14.0.390616200539.issue43463@roundup.psfhosted.org>
2022-03-20 18:42:31antonagestamlinkissue43463 messages
2022-03-20 18:42:31antonagestamcreate