Anonymous
Аргумент "атрибуты" к "чистым" имеет несовместимый тип [arg-type] [закрыто]
Сообщение
Anonymous » 31 янв 2025, 10:21
Код: Выделить всё
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>
Argument "attributes" to "clean" has incompatible type "dict[str, Union[bool, list[str]]]"; expected "Union[Callable[[str, str, str], bool], Union[dict[str, Union[list[str], Callable[[str, str, str], bool]]], dict[str, list[str]], dict[str, Callable[[str, str, str], bool]]], list[str]]" [arg-type]
Здесь Bleach IS
https://pypi.org/project/bleach/образно Тип (источник:
https://github.com/python/typeshed/blob ... er.pyi#l31 )br/>
Код: Выделить всё
_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
1738308098
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> Argument "attributes" to "clean" has incompatible type "dict[str, Union[bool, list[str]]]"; expected "Union[Callable[[str, str, str], bool], Union[dict[str, Union[list[str], Callable[[str, str, str], bool]]], dict[str, list[str]], dict[str, Callable[[str, str, str], bool]]], list[str]]" [arg-type] [/code] Здесь Bleach IS https://pypi.org/project/bleach/образно Тип (источник: https://github.com/python/typeshed/blob/c193cd2a36839c8e6336f350397f51ce52fedd5e/stubs/bleach/bleach/sanitizer.pyi#l31)br/>[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]