Verwirrung über die vom Typ Überprüfung verschachtelte SequenzierungPython

Python-Programme
Guest
 Verwirrung über die vom Typ Überprüfung verschachtelte Sequenzierung

Post by Guest »

Ich habe Code, dass in einem minimalen Beispiel so aussieht.

Code: Select all

from ordered_set import OrderedSet
from collections.abc import Sequence

from typing import NewType, TypeAlias

SeqOverFrag: TypeAlias = Sequence
MotifIdx = NewType("MotifIdx", int)
AOIdx = NewType("AOIdx", int)

x = []
x.append({MotifIdx(1): OrderedSet([AOIdx(1), AOIdx(2)])})

y: Sequence[dict[MotifIdx, Sequence[AOIdx]]] = x
< /code>
, was den Fehler aufwirft < /p>
Incompatible types in assignment (expression has type "list[dict[MotifIdx, OrderedSet[AOIdx]]]", variable has type "Sequence[dict[MotifIdx, Sequence[AOIdx]]]")
Wenn ich x
explizit deklariere, deklariere ich explizit.

Code: Select all

x: list[dict[MotifIdx, Sequence[AOIdx]]] = []
< /code>
Oder wenn ich es direkt initialisieren kannx = [{MotifIdx(1): OrderedSet([AOIdx(1), AOIdx(2)])}]
< /code>
Dann geht der Fehler weg. dass der Typabzug funktioniert hat (?). Ist das ein Fehler in MyPy 
?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post