如何从基类使用重命名的重载方法并保留输出签名?
方法必须在继承自基类的类中有一个新名称
例如:
class BaseApi(api_client.Api):
@typing.overload
def _redirection(
self,
server_index: typing.Optional[int] = None,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: typing_extensions.Literal[False] = ...,
) -> typing.Union[
response_3xx.ResponseFor3XX.response_cls,
response_303.ResponseFor303.response_cls,
]: ...
@typing.overload
def _redirection(
self,
skip_deserialization: typing_extensions.Literal[True],
server_index: typing.Optional[int] = None,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
) -> api_client.ApiResponseWithoutDeserialization: ...
@typing.overload
def _redirection(
self,
server_index: typing.Optional[int] = None,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: bool = ...,
) -> typing.Union[
response_3xx.ResponseFor3XX.response_cls,
response_303.ResponseFor303.response_cls,
api_client.ApiResponseWithoutDeserialization,
]: ...
def _redirection(
self,
server_index: typing.Optional[int] = None,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: bool = False,
):
# implementation
class ApiForGet(BaseApi):
# this class is used by api classes that refer to endpoints by path and http method names
def get(
self,
server_index: typing.Optional[int] = None,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: bool = False,
):
return self._redirection(
server_index=server_index,
stream=stream,
timeout=timeout,
skip_deserialization=skip_deserialization
)
class Redirection(BaseApi):
# this class is used by api classes that refer to endpoints with operationId.snakeCase fn names
def redirection(
self,
server_index: typing.Optional[int] = None,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: bool = False,
):
return self._redirection(
server_index=server_index,
stream=stream,
timeout=timeout,
skip_deserialization=skip_deserialization
)
当我打电话
res = BaseApi._redirection(skip_deserialization=True)
我明白了ApiResponseWithoutDeserialiation
但是当我使用时:
res = ApiForGet._redirection(skip_deserialization=True)
我明白了ApiResponseFor3XX | ApiResponseFor3XX | ApiResponseWithoutDeserialiation
注:我用的是vscode
我能想到的选项是:
我该怎么做? 为什么我输入的内容没有传递到更深层次的调用站点?
这些工作,还有更好的方法吗?
class ApiForGet(BaseApi):
# this class is used by api classes that refer to endpoints by path and http method names
get = BaseApi._redirection
class ApiForGet(BaseApi):
pass
ApiForGet.get = ApiForGet._redirection
这些工作:
class ApiForGet(BaseApi):
# this class is used by api classes that refer to endpoints by path and http method names
get = BaseApi._redirection
class ApiForGet(BaseApi):
pass
ApiForGet.get = ApiForGet._redirection