Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mypy reports functions with identical signatures as not having identical signatures #10274

Closed
ltworf opened this issue Apr 1, 2021 · 4 comments
Labels
bug mypy got something wrong

Comments

@ltworf
Copy link

ltworf commented Apr 1, 2021

Bug Report

Doing a conditional import confuses mypy.

Use mypy on this:

try:
    from emoji import emojize
    reveal_type(emojize)
except ModuleNotFoundError:
    def emojize(string: str, use_aliases=False, delimiters=(':', ':'), variant=None, language='en'):
        return string
    reveal_type(emojize)

The result is

test.py:3: note: Revealed type is 'def (string: builtins.str, use_aliases: builtins.bool =, delimiters: Tuple[builtins.str, builtins.str] =) -> builtins.str'
test.py:5: error: All conditional function variants must have identical signatures
test.py:7: note: Revealed type is 'def (string: builtins.str, use_aliases: builtins.bool =, delimiters: Tuple[builtins.str, builtins.str] =) -> builtins.str'
Found 1 error in 1 file (checked 1 source file)

Expected Behavior

It should work (I copied the function signature from the module) or at the very least return a useful error message.

Complaining about non identical signatures while printing identical signatures doesn't seem the correct behaviour to me.

Your Environment

mypy 0.812
Python 3.9.2

@ltworf ltworf added the bug mypy got something wrong label Apr 1, 2021
@ltworf
Copy link
Author

ltworf commented Apr 2, 2021

Ok reveal type is not so smart, i have to do it in 2 different runs.

Still it'd be nice to show a diff so one can see what's wrong.

@ltworf
Copy link
Author

ltworf commented Apr 2, 2021

It was all particularly difficult because the emoji module is actually not annotated, but mypy is picking a pyi file from

python3-jedi: /usr/lib/python3/dist-packages/jedi/third_party/typeshed/third_party/2and3/emoji.pyi

which annotated the module wrong, skipping some parameters (that maybe were added later on).

So to conclude, this is more of a feature request now.

@bersbersbers
Copy link

bersbersbers commented Oct 17, 2022

Maybe you want to change the title of this issue to state the feature you are requesting. Is it Show a diff between signatures in case of "All conditional function variants must have identical signatures"?

@hauntsaninja
Copy link
Collaborator

I fixed this in #13604

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants