Почему список[список[строка]] не равен списку[Hashable List[Hashable]]Python

Программы на Python
Ответить
Anonymous
 Почему список[список[строка]] не равен списку[Hashable List[Hashable]]

Сообщение Anonymous »

Я борюсь с проверкой типов, используя matplotlib.pyplot.subplot_mosaic.
Я создал следующую функцию, которая генерирует шаблон мозаики и per_subplot_kw:

Код: Выделить всё

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
Когда я звоню

Код: Выделить всё

mosaic, kw = create_mosaic(3)
plt.subplot_mosaic(mosaic, per_subplot_kw=kw)
Я получаю следующую ошибку при вводе:

Код: Выделить всё

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]
Насколько я понимаю, строка неизменяема, поэтому она должна быть Hashable, поэтому список должен включать только значения Hashable и, следовательно, должен быть HashableList?

Подробнее здесь: https://stackoverflow.com/questions/798 ... sthashable
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»