On Sun, Dec 12, 2021 at 05:34:33PM -0800, Paul Bryan wrote: > 1. While I agree that assigning the `Annotated` value to `SomeType` > makes `SomeType` a type alias, what do you call the specific instance > of `Annotated[...]` itself?
Its a type. The specific type is a private implementation detail: >>> type(Annotated[int, 'something']) <class 'typing._AnnotatedAlias'> I just call it a type alias. If you want to be precise, it is an alias to int, augmented with some extra metadata. > To date, I've been referring to it as a > type, but that's also muddying the waters here. No no, it is absolutely a type! _AnnotatedAlias is an instance of type itself: >>> type(typing._AnnotatedAlias) <class 'type'> >>> isinstance(typing._AnnotatedAlias, type) True although Python plays some undocumented(?) shenanigans to make issubclass fail: >>> issubclass(Annotated[int, 'something'], type) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: issubclass() arg 1 must be a class > 2. I've been flyng fast and loose with the term "annotate". No help > from PEP 593, which convolutes the situation with passages such as: I will have a lot more to say on that in another post, replying to Brendan. Later. > Getting concrete: > > Coordinate = Annotated[int, "a graph coordinate", ValueRange(-100, 100)] > ... > @dataclass > class Point: > x: Annotated[Coordinate, "the horizontal coordinate"] > y: Annotated[Coordinate, "the vertical coordinate"] PEP 593 is absolutely clear on the fact that the semantics of the metadata are up to the consumer, and that Python does not require it to be a type or to be treated as a type. It describes the metadata as "an arbitrary list of Python values" so we're fine to shove docstrings in there. -- Steve _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/QZFRKG6A726AGVIFM7FSHIDJIV2ISBHY/ Code of Conduct: http://python.org/psf/codeofconduct/