python / python/mypy

Spurious "progress" during final iteration

Offen
#12,490 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

I discovered this anomaly while debugging mypy in a different situation #12458.

In the final iteration of semanal_main.process_top_levels, I found that self.progress was being set = True by semanal.add_symbol_table_node.
As it turns out, this setting is ignored in process_top_levels as it's the final iteration. However, the local variable final_iteration becomes False, and that could cause problems in some future version of the code.
I suggest in semanal.add_symbol_table_node, you replace

			self.progress = True

with

			if not self.final_iteration:
			    self.progress = True

Now, regarding why a new symbol table node is being added at this late stage, it appears to me to be correct.
What's being added to module X is a dummy definition for a symbol that could not be imported from another module Y because (1) that symbol is undefined in Y or (2) X imports * from Y and that symbol was just added to Y while analyzing Y.
It appears that all possible imported names will get defined, because the SCC ordering guarantees that Y is analyzed before X in situation (2). That's assuming that X and Y are not in a from ... import * cycle.
The cyclic case should be reported as an error, in my opinion. I am filing a separate issue about that.
The dummy definition is a symbol table node with a FakeInfo object, which will get interpreted as Any in later type analysis or error reports. Are you sure you want a FakeInfo? This might lead to some bugs in a future version of the code, and you might want to create a symbol table node with type info for the real Any type.

  • Mypy version used: 0.931

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Suche nach semanal_main.process_top_levels und semanal.add_symbol_table_node und lies anschließend, wie final_iteration und progress während des letzten Durchlaufs interagieren. Erledigt bedeutet, dass progress während dieses Durchlaufs nicht gesetzt wird, während das Verhalten der Dummy-Symboltabelle korrekt bleibt; prüfe außerdem, ob das gemeldete FakeInfo-Problem eine separate Änderung erfordert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.