Skip to content

Please add documentation about needing to re-define inherited overload signatures #10699

Description

@akpircher

Documentation

The documentation you have is pretty good, it usually saves me time.

I, unfortunately, spent too much time today trying to find the right keywords in your documentation, and the issues, trying to find the most pythonic solution for inherited overload signatures:

from __future__ importannotationsimportabcfromtypingimportLiteral, Mapping, overloadclassAdapterBase(abc.ABC):
@overloaddefget_map_or_value(self, *, as_dict: Literal[True]) ->Mapping[str, str]:
...
@overloaddefget_map_or_value(self, *, as_dict: Literal[False] = ...) ->str:
...
@overloaddefget_map_or_value(self, *, as_dict: bool= ...) ->Mapping[str, str] |str:
...
@abc.abstractmethoddefget_map_or_value(self, *, as_dict: bool=False) ->Mapping[str, str] |str:
raiseNotImplementedErrorclassConcreteAdapter1(AdapterBase):
# fails strict no-untyped-def checksdefget_map_or_value(self, *, as_dict):
ifas_dict:
return {"somekey": "somevalue"}
return"somevalue"classConcreteAdapter2(AdapterBase):
# Signature of "get_map_or_value" incompatible with supertype "AdapterBase" [override]defget_map_or_value(self, *, as_dict: bool=False) ->Mapping[str, str] |str:
ifas_dict:
return {"someOtherKey": "someOtherValue"}
return"someOtherValue"classDoSomethingElse:
def__init__(self, adapter: AdapterBase) ->None:
# needs to know about function names, parameters, and return typesself.adapter=adapter

My intuition in this scenario told me that the overloads could be inherited, and thus I just needed to provide the generic typedef and go on my merry way. That is, clearly, not the case and it took me a while to find #5146, and consequently, python/typing#269.

It would be nice if the documentation could mention that overload variants need to be re-defined in child/concrete classes. It would also clarify that this "edge case", or ones similar to it, is not an edge case, it's by design.

Here are some places where I went looking for answers, and perhaps someone else might too:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions