Anonymous
Аргумент "атрибуты" к "чистым" имеет несовместимый тип [arg-type] [закрыто]
Сообщение
Anonymous » 01 фев 2025, 12:11
Код: Выделить всё
import bleach
a = {
'a': True,
'b': ['text'],
'c': []
}
b = a.copy();
bleach.clean( # line 11
'string', tags=tag_names, attributes=b, strip=True)
< /code>
из строки 11 < /p>
аргумент «атрибуты» к «чистым» имеет несовместимый тип »Dict [str,
Union [Bool, List [str]]] "; Ожидаемый "Союз [Callible [[str, str, str],
bool], Union [dict [str, union [list [str], callable [[str, str],
bool] ]], dict [str, list [str]], dict [str, callable [[str, str, str],
bool]]], list [str]] "[arg-type] < /p >
здесь отбеливатель - https://pypi.org/project/bleach/ написан Ожидается, что будет соответствовать _attributes
Тип (Источник:
https://github.com/python/typeshed/blob ... er.pyi#l31 ).
Код: Выделить всё
_AttributeFilter: TypeAlias = Callable[[str, str, str], bool]
_AttributeDict: TypeAlias = dict[str, list[str] | _AttributeFilter] | dict[str, list[str]] | dict[str, _AttributeFilter]
_Attributes: TypeAlias = _AttributeFilter | _AttributeDict | list[str]
Как я должен ввести аннотацию переменной a ?
Подробнее здесь:
https://stackoverflow.com/questions/793 ... e-arg-type
1738401089
Anonymous
[code]import bleach a = { 'a': True, 'b': ['text'], 'c': [] } b = a.copy(); bleach.clean( # line 11 'string', tags=tag_names, attributes=b, strip=True) < /code> из строки 11 < /p> аргумент «атрибуты» к «чистым» имеет несовместимый тип »Dict [str, Union [Bool, List [str]]] "; Ожидаемый "Союз [Callible [[str, str, str], bool], Union [dict [str, union [list [str], callable [[str, str], bool] ]], dict [str, list [str]], dict [str, callable [[str, str, str], bool]]], list [str]] "[arg-type] < /p > здесь отбеливатель - https://pypi.org/project/bleach/ написан Ожидается, что будет соответствовать _attributes [/code] Тип (Источник: https://github.com/python/typeshed/blob/c193cd2a36839c8e6336f350397f51ce52fedd5e/stubs/bleach/bleach/sanitizer.pyi#l31).[code]_AttributeFilter: TypeAlias = Callable[[str, str, str], bool] _AttributeDict: TypeAlias = dict[str, list[str] | _AttributeFilter] | dict[str, list[str]] | dict[str, _AttributeFilter] _Attributes: TypeAlias = _AttributeFilter | _AttributeDict | list[str] [/code] Как я должен ввести аннотацию переменной a ? Подробнее здесь: [url]https://stackoverflow.com/questions/79397987/argument-attributes-to-clean-has-incompatible-type-arg-type[/url]