Skip to content

Conditional function variants result in warning despite having identical types (only varying in parameter names) #10575

Closed
@posita

Description

@posita

These both result in the All conditional function variants must have identical signatures warning:

try:
    from math import comb
except ImportError:
    def comb(n: int, k: int) -> int:  # All conditional function variants must have identical signatures
        return int(factorial(n) / factorial(k) / factorial(n - k))
import sys
if sys.version_info >= (3, 8):
    from math import comb
else:
    def comb(n: int, k: int) -> int:  # All conditional function variants must have identical signatures
        return int(factorial(n) / factorial(k) / factorial(n - k))

Typeshed conditionally defines math.comb as def comb(__n: int, __k: int) -> int: .... Changing the parameter names in either of the above examples to match the typeshed signature silences the warning:

try:
    from math import comb
except ImportError:
    def comb(__n: int, __k: int) -> int:  # <no more warning>
        return int(factorial(__n) / factorial(__k) / factorial(__n - __k))

I think this came up before in #1168 (and via #1801, but, given the above, I don't think #698 addresses this).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions