Allow extracting/referring type from things like dictionary, dataclasses & Pydantic models

I also tried to propose a simillar thing here though I didn’t made any progress since then (I wanted to approach other package and type-checker maintainers to see if they would be willing to support this. Unfortunately, I was abit busy and didn’t get back to this).

I also drafted a basic PEP with my version of this proposal.

Here are a few problematic points you may want to consider:

  1. If the syntax uses literal strings, it may present some problems with regards to stringified annotations. We need to be able to distinguish between "name" as the literal name of the field, and "name" which can potentially can refer to a type (A class which may be called name and is available in the same scope)
  2. We need to consider what should be available and on what conditions. Person["name"] may refer to either an attribute or an item. A class may support both ways, it may define methods in its class body. Should they be accessible as well? What about properties? There are a lot of things to consider here.

I think if we’re able to answer these features thoroughly, this has the potential to give a massive boost to type-checkers and package maintainers.