gemäß der Dokumentation __len __ und __getItem __ sind ausreichend. Mein Typ-Hintergrund beschwert sich jedoch über die Implementierung von __getItem __ , obwohl meine Implementierung den Python-Dokumenten folgt.
Code: Select all
from collections.abc import Sequence
from typing import override
class MySeq(Sequence[float]):
def __init__(self):
self._data: list[float] = list()
@override
def __len__(self) -> int:
return len(self._data)
@override
def __getitem__(self, key) -> float: # Type annotation is missing for parameter "key"
return self._data[key] # Return type is unknown
< /code>
[*] Wie tippe ich einen Hinweisschlüssel < /code>? Nur Schlüssel: Int
Was ist mit dem Rückgabetyp los? Die vollständige Warnung ist "float" ist "Sequenz [float]"