python / python/mypy

Get rid of fake TypeInfo's for TypedDicts

Open
#8,620 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug priority-1-normal refactoring topic-typed-dict
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

We currently create fake TypeInfos to store TypedDicts. This used to cause various issues, in particular, currently the type of a TypedDict "class object" in runtime context is () -> SomeTypedDict, where the return type is an instance of the fake TypeInfo.

We can probably fix latter by just constructing a reasonable type, but a more global solution would be to get rid of the fake TypeInfo entirely. It is not needed for anything and just complicates things. We will need to put some symbol node in the symbol table, so we would need a new SymbolNode subclass (or reuse TypeAlias, so a TypedDict definition A = TypedDict('A' {'x': int, 'y': int}) will be very similar to A = Dict[str, int]).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing where TypedDict definitions create fake TypeInfos and how their symbols are stored in the symbol table. Evaluate a new SymbolNode subclass or TypeAlias representation, then verify that TypedDicts no longer require fake TypeInfos and that their runtime-context class-object type is reasonable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.