python / python/mypy

Refurb crashes on Mypy 1.7.0

Aperta
#16,497 18 commenti 6 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug question topic-mypyc
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug Report

Refurb is a project that depends on Mypy internals to work properly. Since v1.7.0 of Mypy (specifically since https://github.com/python/mypy/pull/15770 was merged), Refurb no longer works, and instead emits the following error:

$ refurb file.py
interpreted classes cannot inherit from compiled traits

See also: https://github.com/dosisod/refurb/issues/305

To Reproduce

$ pip install refurb==1.22.2 mypy==1.7.0
$ touch file.py
$ refurb file.py
interpreted classes cannot inherit from compiled traits

Expected Behavior

Refurb doesn't crash.

Actual Behavior

Refurb is crashing.

Your Environment

  • Mypy version used: 1.7.0
  • Python version used: 3.11.5

Background

#15770 added a @trait decorator to TraverserVisitor, meaning 3rd party (interpreted) programs can no longer inherit from TraverserVisitor:

https://github.com/python/mypy/blob/c6cb3c6282003dd3dadcf028735f9ba6190a0c84/mypy/traverser.py#L97-L99

I tried a bunch of different workarounds including making a custom __new__ method, copy-and-pasting TraverserVisitor into my code and removing the @trait, but alas nothing is working, and so I had to pin Mypy to <= v1.6.1 in Refurb, which will prevent users from using the newest version of Mypy with Refurb. Using the non-compiled version of Mypy doesn't have this issue, but doing so would be far too slow, especially since Refurb parses/walks the full, fine-grained AST tree (similar to mypyd).

My question: How should I get around this? Is there anything I can do on my end, or does something in Mypy have to change? I would think that allow_interpreted_subclasses=True would nullify the inheritance restriction imposed by @trait, but that doesn't seem to be the case.

There is also the bigger question of how 3rd parties should safely use Mypy internals (or if they even should in the first place). Currently Mypy internals are not versioned and can change with any release. In addition, certain parts of Mypy are hard/impossible to use outside of Mypy itself, whether that's because they don't work, crash, or require lots of moving parts because they weren't meant to be used in a stand-alone environment. I know that standardizing/stabilizing Mypy's internals so that 3rd parties can use them is probably not a major priority, but I thought I would bring it up to gauge how you all feel about it. I could elaborate more but I want to keep this short. I can open a separate issue for this if need be.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci il crash con refurb 1.22.2, mypy 1.7.0 e un file vuoto, come mostrato. Leggi mypy/traverser.py intorno alle righe 97-99 e ispeziona PR #15770, quindi confronta il comportamento compilato e non compilato. Il lavoro è completato quando Refurb non va più in crash con Mypy 1.7.0 mantenendo il comportamento richiesto di attraversamento dell’AST.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.