TransformVisitor (and StrConv) are slightly out-of-sync with node definitions

Open
#2,109 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Review TransformVisitor in mypy.treetransform and StrConv in mypy.strconv against the node definitions in mypy.nodes; start with the listed visitor methods and attributes. Check related visitors for similar mismatches, then add coverage that detects missing copied attributes and verify the listed cases are handled.

Written by the indexing model from the issue text.

Description

refactoring

I recently noticed that mypy.treetransform.TransformVisitor seems to be slightly out-of-sync with the nodes within mypy.nodes.

For example...

  • visit_func_def isn't copying over the is_generator, is_coroutine, and is_awaitable_coroutine attributes
  • visit_var isn't copying over the is_suppressed_import attribute
  • visit_with_statement isn't copying over is_async
  • visit_class_def isn't copying over has_incompatible_baseclass

Currently, it doesn't seem like these omissions are too harmful since the only place we use TransformVisitor is within TypeTransformVisitor (which only expands types). However, I could see this might lead to subtle bugs in the future, so it's probably worth fixing this now and perhaps coming up with some sort of test that will automatically catch these sorts of discrepancies in the future.

mypy.strconv.StrConv also seems to have similar issues, though it's probably even less of a priority. I haven't really checked the other visitors, so I don't know if they're similarly desynched.

(I'm filing this issue to make sure I don't forget about it).

Dominant language
Python
Stars
20.6k
Forks
3.3k
Avg merge
1d 18h
Merged PRs (30d)
54

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.

More from python/mypy

All issues in python/mypy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.