Update types_base.py

fix stringify_type
master
Lorenz Diener 2025-06-18 16:25:16 +03:00 zatwierdzone przez GitHub
rodzic d845707f14
commit 6b769779d9
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 11 dodań i 7 usunięć

Wyświetl plik

@ -1,4 +1,5 @@
from __future__ import annotations # python < 3.9 compat from __future__ import annotations # python < 3.9 compat
import typing
from typing import List, Union, Optional, Dict, Any, Tuple, Callable, get_type_hints, TypeVar, IO, Generic, ForwardRef from typing import List, Union, Optional, Dict, Any, Tuple, Callable, get_type_hints, TypeVar, IO, Generic, ForwardRef
from datetime import datetime, timezone from datetime import datetime, timezone
import dateutil import dateutil
@ -215,13 +216,16 @@ def stringify_type(tp):
if origin is not None: if origin is not None:
origin_module = origin.__module__ origin_module = origin.__module__
origin_name = origin.__qualname__ origin_name = origin.__qualname__
if origin_module in ("mastodon.return_types", "mastodon.types_base"): if origin in [list, EntityList, PaginatableList, NonPaginatableList]:
type_str = origin_name if origin_module in ("mastodon.return_types", "mastodon.types_base"):
else: type_str = origin_name
type_str = f"{origin_module}.{origin_name}" else:
if args: type_str = f"{origin_module}.{origin_name}"
arg_strs = [stringify_type(arg) for arg in args] if args:
type_str += f"[{', '.join(arg_strs)}]" arg_strs = [stringify_type(arg) for arg in args]
type_str += f"[{', '.join(arg_strs)}]"
elif origin in [Union, Optional]:
type_str = stringify_type(args[0])
return type_str return type_str
else: else:
module = getattr(tp, "__module__", "") module = getattr(tp, "__module__", "")