Я использую подсказки Python и Type с типичными библиотеками и типами , и не могу пройти следующий код с ошибками вне:
import numpy as np
import pandas as pd
import nb_mypy
%load_ext nb_mypy
%reload_ext nb_mypy
%nb_mypy On
%nb_mypy DebugOff
from typing import Tuple, Union, Dict, List, Any
from types import ModuleType # FrameType, TracebackType
i: List[str]
j: List[ModuleType] # I couldn't find the Type Hint for modules...
for i, j in zip(
['numpy', 'pandas'],
[np, pd]):
print(f"{i} used in this code is version {j.__version__}")
< /code>
На данный момент я получаю ошибки: < /p>
error: Incompatible types in assignment (expression has type "str", variable has type "list[str]") [assignment]
error: "list[Module]" has no attribute "__version__" [attr-defined]
Я тоже попробовал это с любым и получил это вместо этого, что не лучше:
error: Incompatible types in assignment (expression has type "str", variable has type "list[str]") [assignment]
error: "list[Any]" has no attribute "__version__" [attr-defined]
Подробнее здесь: https://stackoverflow.com/questions/767 ... -in-python
Как я могу указать модуль в виде подсказки типа в Python? ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение