On 1/21/22 3:43 PM, Gregory Beauregard via Typing-sig wrote:
While I agree with the sentiment and the comments below, I think we should nevertheless always allow `Annotated` on the outside, even in the case of `ClassVar` and `Final`. In https://bugs.python.org/msg411067 a user is complaining about the inability to place `Annotated` on the outside of `ClassVar`, causing difficulty.
I've seen several complaints on the mailing list that there's too much tension between typing users of annotation space and non-typing users of annotation space. If we want to continue to claim typing annotations aren't going to interfere with people we owe it to them to take issues with our blessed typing-friendly annotation format (`Annotated`) seriously.
In that vein, it seems to me the cost of typing being a good citizen to other users of annotations should require us to always accept `Annotated` on the outside of annotations to avoid forcing the burden of being able to parse typing on all other users of annotations. If someone wishes to annotate a specific inner type with `Annotated`, then they are already buying into being able to parse typing anyway.
On 1/21/22 5:50 PM, Mehdi2277 wrote:
If you add [the requirement that mixing Annotated and Required must force Required on the outside and disallow Annotated on the outside], I'll need to add logic that works around this for runtime annotation using library. [...] I would expect any other library using Annotated for it's purpose of examining other metadata will need similar edge case logic to handle typeddicts properly.
Annotated I ideally would view as purely Identity to any typeform. [...]
I am receptive to this line of argument and was thinking there might be users of Annotated[T, ...] that wanted it to always be possible to put Annotated[] as the outermost item. Medhi's example confirms this suspicion. Therefore: (1) I'm looking at leaving in my current language in PEP 655 that allows (Not)Required[] and Annotated[] to be nested in *any* order. In particular Annotated[] is allowed to wrap (Not)Required[]. - I plan to add some explanatory language as to *why* I'm allowing nesting in any order. (2) I think that ClassVar[] and Final[] should be altered to also allow Annotated[] to be mixed in with any nesting order, but I'll looking at leaving that work to a future PEP, since it feels unrelated to the TypedDict-specific alterations that PEP 655 is making. - So I'll mention this inconsistency in PEP 655 (but not attempt to amend it immediately). -- David Foster | Seattle, WA, USA Contributor to TypedDict support for mypy