用法:
@typing.type_check_only
裝飾器將類或函數標記為在運行時不可用。
此裝飾器本身在運行時不可用。如果實現返回私有類的實例,它主要用於標記在類型存根文件中定義的類:
@type_check_only class Response: # private or not available at runtime code: int def get_header(self, name: str) -> str: ... def fetch_response() -> Response: ...
請注意,不建議返回私有類的實例。通常最好將此類課程公開。
相關用法
- Python typing.get_type_hints用法及代碼示例
- Python typing.Concatenate用法及代碼示例
- Python typing.Optional用法及代碼示例
- Python typing.Final用法及代碼示例
- Python typing.TypedDict.__optional_keys__用法及代碼示例
- Python typing.Protocol用法及代碼示例
- Python typing.NoReturn用法及代碼示例
- Python typing.TypedDict.__total__用法及代碼示例
- Python typing.is_typeddict用法及代碼示例
- Python typing.TypeVar用法及代碼示例
- Python typing.AsyncGenerator用法及代碼示例
- Python typing.final用法及代碼示例
- Python typing.ClassVar用法及代碼示例
- Python typing.ParamSpec用法及代碼示例
- Python typing.Literal用法及代碼示例
- Python typing.overload用法及代碼示例
- Python typing.TYPE_CHECKING用法及代碼示例
- Python typing.TypedDict用法及代碼示例
- Python typing.List用法及代碼示例
- Python typing.Generic用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 typing.type_check_only。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。