Fine-grained: Inconsistent behavior for nested NewType

Aperta
#4,615 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Start with the fine-grained incremental mode test case testRefreshNestedNewType and run it through both increments described for a.py and b.py. Compare the first and second outputs for the nested NewType declarations; done means both runs produce identical errors for each example.

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

Descrizione

bug priority-2-low topic-fine-grained-incremental

The output of the second increment of this fine-grained incremental mode test case doesn't generate an error, even though nothing relevant has changed:

[case testRefreshNestedNewType]
import a
[file a.py]
from typing import Union, NewType
import b

def f(self) -> None:
    X = NewType('X', A)

A = str
[file b.py]
y = 0
[file b.py.2]
y = ''
[out]

Here's the output:

a.py:5: error: Argument 2 to NewType(...) must be subclassable (got A?)
==

The expected output would be identical for both runs.

The output from the first and second runs also does not match for this slightly different test case:

[case testRefreshNestedNewType]
import a
[file a.py]
from typing import Union, NewType
import b

def f(self) -> None:
    X = NewType('X', A)

A = Union[int, str]

[file b.py]
y = 0
[file b.py.2]
y = ''
[out]

Here's the output (again expected to be identical):

a.py:5: error: Argument 2 to NewType(...) must be subclassable (got A?)
==
a.py:5: error: Argument 2 to NewType(...) must be subclassable (got "Union[int, str]")

It looks like forward references within NewType declarations behave inconsistently.

Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Merge medio
1g 18h
PR unite (30g)
54

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.

Altre issue di python/mypy

Tutte le issue di python/mypy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.