|
|
Subscribe / Log in / New account

When and how to evaluate Python annotations

When and how to evaluate Python annotations

Posted Jun 15, 2021 6:53 UTC (Tue) by cpitrat (subscriber, #116459)
Parent article: When and how to evaluate Python annotations

> There are clearly existing real-world, run-time uses of type annotations that would be adversely affected by this change.

Unless I missed something, none are mentioned in the article. Were they mentioned in the discussion? I wonder what these usages are.


to post comments

When and how to evaluate Python annotations

Posted Jun 15, 2021 23:49 UTC (Tue) by timrichardson (subscriber, #72836) [Link] (5 responses)

I think you missed the discussion in the article of pydantic, which is a dependency of FastAPI. There were some others mentioned, but pydantic was the headline.

When and how to evaluate Python annotations

Posted Jun 16, 2021 6:53 UTC (Wed) by cpitrat (subscriber, #116459) [Link] (2 responses)

No I didn't. I just pasted the wrong part of the article. Silly me!

What I wanted to ask is whether there's really any usage of annotations for something else than typing, so questioning rather the objections to this part:
"restrict annotations to just type hints"

When and how to evaluate Python annotations

Posted Jun 16, 2021 11:18 UTC (Wed) by mathstuf (subscriber, #69389) [Link] (1 responses)

I remember seeing a macro system based on it. No idea how serious it was or how prevalent, but I really don't like the precedent of "here's an abstract ball, do what you want with it however you see it" then later the developers coming in and saying "so we said it was an abstract ball, but we're making it a bowling ball now; sorry to anyone who was playing basketball with it before, but you're going to have a bad time".

When and how to evaluate Python annotations

Posted Jun 16, 2021 11:31 UTC (Wed) by cpitrat (subscriber, #116459) [Link]

Yeah I get that. I'm quite curious about other applications and especially about whether they can mix with typing. I assume not, which by itself makes having annotations abstract in the first place a dubious choice.

When and how to evaluate Python annotations

Posted Jun 17, 2021 4:36 UTC (Thu) by jamesh (guest, #1159) [Link] (1 responses)

From a quick look at the docs, pydantic is treating annotations as types: the same as static type checkers. The same seems to go for attrs. So they don't seem to be examples of using annotations for non-typing purposes.

When and how to evaluate Python annotations

Posted Nov 28, 2022 17:06 UTC (Mon) by agarbanzo (guest, #162411) [Link]

I think there's a lot of use cases stemming from PEP 593: https://peps.python.org/pep-0593/. It provides a way to attach arbitrary metadata which is ignored by static type checkers. So pretty much by definition any use of PEP 593 is going to be non-typing related. The PEP even gives an example use case: https://peps.python.org/pep-0593/#combining-runtime-and-s...

When and how to evaluate Python annotations

Posted Aug 31, 2021 16:10 UTC (Tue) by tanriol (guest, #131322) [Link]

The `argh` argument parsing libary uses function argument annotations as per-argument documentation when generating the help output. Maybe there are some other "minor" uses in the ecosystem.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds