python / python/mypy

Functions with type variable value restriction lose some AST information

Open
#14,706 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

There are a bunch of mypy AST attributes that mypy.treetransform.TransformVisitor does not propagate when copying AST nodes. This causes issues in functions using a type variable restriction, since function bodies of such functions are transformed using this visitor before type checking. Based on a user report, I noticed that async-related flags aren't propagated. I also noticed a few others, including dataclass transform state. It's not clear if all of these are causing actual issues, but some of them might.

We should go through all AST nodes and double check that all relevant state is being copied. Not sure if there is an easy way to test exhaustively that we don't miss any attributes as AST attributes are added.

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 with mypy.treetransform.TransformVisitor and compare the attributes it copies against the state on all AST nodes, especially async-related flags and dataclass transform state. Check existing coverage for functions using restricted type variables, then add tests that confirm transformed nodes retain relevant state; done means relevant AST state is consistently preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.