python / python/mypy

Semantic analyzer confuses a function with a module

Aperta
#7,203 7 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug false-positive priority-0-high semantic-analyzer
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

The following code creates a package structure that demonstrates what I think is a bug in mypy's new semantic analyzer.

from os import makedirs

makedirs('src/core')
makedirs('src/stuff')

open('src/__init__.py', 'w').write("""
# nothing here
""")

open('src/core/__init__.py', 'w').write("""
from .run import config
""")

open('src/core/run.py', 'w').write("""
from ..stuff import somefunction

config = None

somefunction()
""")

open('src/stuff/__init__.py', 'w').write("""
from .somemore import more
from .somefunction import somefunction
""")

open('src/stuff/somefunction.py', 'w').write("""
def somefunction():
    print("Hello, World!")
""")

open('src/stuff/somemore.py', 'w').write("""
def more():
    from ..core import config
""")

When checking the created src package with mypy 0.720 and Python 3.7, I get the following error:

src/core/run.py:6: error: Module not callable

What mypy thinks is a module is actually a function. It just has the same name as its containing module.

When I check with --no-new-semantic-analyzer, I do not get this error.

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

Ricrea il pacchetto src generato dal corpo dell'issue ed esegui mypy 0.720 con e senza --no-new-semantic-analyzer, concentrandoti su src/core/run.py e src/stuff/somefunction.py. Traccia il motivo per cui somefunction viene risolto come modulo invece che come funzione chiamabile; il lavoro è completato quando il nuovo analizzatore semantico accetta la chiamata e il comportamento è coperto da un test di regressione.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.