Uh oh!
There was an error while loading. Please reload this page.
Fix overloading with a typevar missing - #11617
Conversation
This comment has been minimized.
This comment has been minimized.
A5rocks
commented
Nov 25, 2021
oh that broke terribly didn't it. |
This comment has been minimized.
This comment has been minimized.
sobolevn
commented
Nov 26, 2021
I think that the given example is not ideal. Because typevar should not even be used in this example: T=typing.TypeVar("T", bound=A)
@typing.overloaddeff(a: T) ->None:
...
@typing.overloaddeff(*, copy: bool=False) ->None:
...
deff(a: T= ..., *, copy: bool=False) ->None:
...Should be: @typing.overloaddeff(a: A) ->None:
...
@typing.overloaddeff(*, copy: bool=False) ->None:
...
deff(a: A= ..., *, copy: bool=False) ->None:
...Maybe you should also add an example, where |
The given example was an oversimplification of the original, which can be simplified to: importtypingimportcollections.abcascollectionsclassBaseSlashCommand:
...
BaseSlashCommandT=typing.TypeVar("BaseSlashCommandT", bound=BaseSlashCommand)
@typing.overloaddefwith_slash_command(command: BaseSlashCommandT, /) ->BaseSlashCommandT:
...
@typing.overloaddefwith_slash_command(
*, copy: bool=False
) ->collections.Callable[[BaseSlashCommandT], BaseSlashCommandT]:
...
defwith_slash_command(
command: BaseSlashCommandT= ..., /, *, copy: bool=False
) ->typing.Union[BaseSlashCommandT, collections.Callable[[BaseSlashCommandT], BaseSlashCommandT]]:
...The original can be found at https://github.com/FasterSpeeding/Tanjun/blob/7edec0fa4418718343826f9c6489bd817c4a9b47/tanjun/components.py#L590-L604 (yes I know the |
A5rocks
commented
Nov 28, 2021
Went through some issues that seemed partially related -- it looks like #9023 gets fixed by this too! |
Time for a quick run of mypy-primer!
Diff from mypy_primer, showing the effect of this PR on open source code: Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/abc.py:3139: error: Overloaded function implementation cannot satisfy signature 2 due to inconsistencies in how they use type variables [misc]- tanjun/abc.py:3205: error: Overloaded function implementation cannot satisfy signature 2 due to inconsistencies in how they use type variables [misc] |
A5rocks
commented
May 29, 2023
Remade in #15320 |
Description
This fixes this following program:
This also fixes#9023.
Test Plan
I haven't added any tests yet, I plan to do that based on mypy primer output (still not sure this works...).