Better message for "Function ... could always be true"
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Consider this example:
def f(x: int) -> str: pass
if f:
pass
It generates this error:
t.py:3: error: Function "Callable[[int], str]" could always be true in boolean context [truthy-function]
Instead, if we have a direct reference to a function definition, we could generate a message like this which would be clearer, especially if the signature is complex:
t.py:3: error: Function "f" could always be true in boolean context [truthy-function]
There are at least these different cases to consider:
- Direct reference to a function using a short name of a function (similar to the above example).
- Direct reference to a function using a module prefix (e.g.
if mod.func:). - Reference to a method (e.g.
if obj.method:). - Reference to a variable/attribute (
Varnode) with typeCallable[...](in this case we could show the name of the variable/attribute or the callable type -- both would be okay). - Any other expression that produces a callable value, such as
if func():wherefuncreturns a callable. Here the best option is to show the callable type as we do now.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das Beispiel zu reproduzieren, und untersuche, wie die [truthy-function]-Diagnose aufrufbare Ausdrücke formatiert. Vergleiche direkte Funktionsreferenzen, modulqualifizierte Funktionen, Methoden, aufrufbare Variablen oder Attribute sowie Ausdrücke, die aufrufbare Objekte zurückgeben. Die Aufgabe ist erledigt, wenn direkte Referenzen gegebenenfalls den klareren Funktionsnamen verwenden, während andere Fälle einen nützlichen Typ oder eine nützliche Beschreibung des aufrufbaren Objekts oder Ausdrucks beibehalten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100