python / python/mypy

support modules as parameters in generic functions

Offen
#6,132 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature priority-1-normal
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Note: if you are reporting a wrong signature of a function or a class in
the standard library, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues

Please provide more information to help us understand the issue:

  • Are you reporting a bug, or opening a feature request?

I think this is a bug (the behaviour is consistent with other kind of objects)

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
import typing
T = typing.TypeVar('T')
def same(obj: T) -> T:
    return obj
add = same(3).__add__
TypeVar = same(typing).TypeVar
  • What is the actual behavior/output?
minimal.py:6: error: Module has no attribute "TypeVar"
  • What is the behavior/output you expect?

[no errors]

  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?

0.650

  • What are the mypy flags you are using? (For example --strict-optional)
[mypy]
disallow_untyped_defs = True

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

Beginnen Sie, indem Sie das Beispiel minimal.py mit der gemeldeten mypy-Konfiguration ausführen, und bestätigen Sie, dass der Fehler „Module has no attribute "TypeVar"“ nicht auftritt. In diesem Issue wird keine Quelldatei und kein Test genannt; verfolgen Sie, wie Ergebnisse generischer Funktionen behandelt werden, wenn das Argument ein Modul ist, und fügen Sie anschließend eine Abdeckung hinzu, die das erwartete Verhalten ohne Fehler zeigt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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