dosisod / refurb

A tool for refurbishing and modernizing Python codebases
GNU General Public License v3.0
2.48k stars 54 forks source link

Experimental/use standalone visitor #309

Closed bzoracler closed 11 months ago

bzoracler commented 11 months ago

This is an experimental PR to use a standalone imitation of mypy.visitor.TraverserVisitor, allowing reversion of the recent pinning of mypy to <1.7.

The visitor module traverser.py is produced from generated code (not handwritten) on mypy==1.7.0. The style (including explicit re-export of the nodes, @functools.singledispatch, nothing under TYPE_CHECKING blocks even though the imports aren't used at runtime) is deliberate to allow the visitor to be compiled by mypyc if you wish (which has a lot of quirks, and is not fully compatible with standard Python in my experience).

The visitor has a different API (visitor.accept(node), not node.accept(visitor)) because mypy nodes can't accept visitors that are not subclassed from mypy's own visitors (mypyc fails type incompatibilities at runtime), and you can't subclass mypy.traverser.TraverserVisitor with the mypy==1.7.0 change.

Setting this as a draft PR - feel free to merge, change, and/or discard as appropriate.

bzoracler commented 11 months ago

Upgraded status as it looks like it's a release blocker (https://qa.debian.org/excuses.php?package=mypy)

dosisod commented 11 months ago

Thanks! This looks good as is, so I'll go ahead and merge it. I'll make sure to publish a release by EOD.

Closes #305