Warum ist list[list[string]] nicht gleich list[Hashable List[Hashable]]?Python

Python-Programme
Anonymous
 Warum ist list[list[string]] nicht gleich list[Hashable List[Hashable]]?

Post by Anonymous »

Ich habe Probleme mit Typprüfungen mit matplotlib.pyplot.subplot_mosaic.
Ich habe die folgende Funktion erstellt, die das Mosaikmuster und den per_subplot_kw generiert:

Code: Select all

def create_mosaic(num_rows):
def base_panel(idx):
return [f"rgb{idx}", f"hist{idx}", f"polar{idx}"]

mosaic = list()
per_subplot_kw = dict()

for i in range(num_rows):
mosaic.append(base_panel(i))
per_subplot_kw[f"polar{i}"] = dict(projection="polar")
return mosaic, per_subplot_kw
Wenn ich anrufe

Code: Select all

mosaic, kw = create_mosaic(3)
plt.subplot_mosaic(mosaic, per_subplot_kw=kw)
Ich erhalte den folgenden Tippfehler:

Code: Select all

Diagnostics:
1. No overloads for "subplot_mosaic" match the provided arguments [reportCallIssue]
2. Argument of type "list[list[str]]" cannot be assigned to parameter "mosaic" of type "list[HashableList[Hashable]]" in function "subplot_mosaic"
  "list[list[str]]" is not assignable to "list[HashableList[Hashable]]"
    Type parameter "_T@list" is invariant, but "list[str]" is not the same as "HashableList[Hashable]"
    Consider switching from "list" to "Sequence" which is covariant [reportArgumentType]
3. Argument of type "dict[str, dict[str, str]]" cannot be assigned to parameter "per_subplot_kw" of type "dict[Hashable | tuple[Hashable, ...], dict[str, Any]] | None" in function "subplot_mosaic"
  Type "dict[str, dict[str, str]]" is not assignable to type "dict[Hashable | tuple[Hashable, ...], dict[str, Any]] | None"
    "dict[str, dict[str, str]]" is not assignable to "dict[Hashable | tuple[Hashable, ...], dict[str, Any]]"
      Type parameter "_KT@dict" is invariant, but "str" is not the same as "Hashable | tuple[Hashable, ...]"
    "dict[str, dict[str, str]]" is not assignable to "None" [reportArgumentType]
Nach meinem Verständnis ist str unveränderlich, also sollte es Hashable sein, also sollte die Liste nur Hashable-Werte enthalten und daher eine HashableList sein?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post
  • Konvertieren Sie List> in eine List
    by Anonymous » » in Java
    0 Replies
    114 Views
    Last post by Anonymous
  • Konvertieren Sie List> in eine List
    by Guest » » in Java
    0 Replies
    96 Views
    Last post by Guest
  • MAP > zur Liste > Verwenden der Stream -API
    by Anonymous » » in Java
    0 Replies
    100 Views
    Last post by Anonymous
  • Android (Kotlin / Java) List / Array -> Rost Vec Konvertierung mit JNI
    by Anonymous » » in Android
    0 Replies
    68 Views
    Last post by Anonymous
  • Machen Sie eine python-benutzerdefinierte Klassen-sortierbare, hashable
    by Anonymous » » in Python
    0 Replies
    26 Views
    Last post by Anonymous