Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 18819

Remove Annotations from typing.Annotated

$
0
0

Let's say I have some type aliases, maybe

Point3D = Annotated[tuple[float, float, float], "A 3D Point"]Points = Annotated[list[Point3D, list[float]], "A collection of points"]

If I try to print Points, I get

typing.Annotated[list[typing.Annotated[tuple[float, float, float], 'A 3D Point'] | list[float]], 'A collection of points']

I want to only get the list[tuple[float, float, float]] part. I tried using typing.get_args(Points)[0] but that just gives this:

list[typing.Annotated[tuple[float, float, float], 'A 3D Point'] | list[float]]

Where there is still the unwanted 'A 3D Point'. How can I achieve this? I tried replacing it with the ", '.*?' regex, but that didn't work, and I'm not experienced enough with regex to be able to figure out why.

Note:I can't just change all the Annotated types to normal type hints because I still need that annotation content to be displayed elsewhere.


Viewing all articles
Browse latest Browse all 18819

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>