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

Add a check for duplicate union members #50

Merged
merged 3 commits into from
Jan 10, 2022

Conversation

Akuli
Copy link
Collaborator

@Akuli Akuli commented Dec 28, 2021

Discussed in microsoft/pyright#2753.

The code for detecting Union[str, str] is a bit fragile, as it assumes you do from typing import Union. I can remove it if that is better. Typeshed uses | syntax anyway.

@JelleZijlstra
Copy link
Collaborator

Thanks! I think the typing.Union check is fine, but it would be good if the error message said what the duplicate member is (e.g. 'Duplicate enum member "str"')—it may not be obvious if you have a very complicated Union.

Out of curiosity, did this find any other instances in typeshed?

@Akuli
Copy link
Collaborator Author

Akuli commented Dec 29, 2021

I improved the error message. It found these:

stdlib/difflib.pyi:8:46: Y016 Duplicate union member 'Callable[[str], bool]'
stdlib/argparse.pyi:295:37: Y016 Duplicate union member 'Callable[[str], _T]'
stdlib/argparse.pyi:314:41: Y016 Duplicate union member 'Callable[[str], _T]'

The first two have Text and str in Python 2 stubs, and str and str in Python 3 stubs. The last one is in a Python 3 only class that also had Text and str for some reason, but python/typeshed#5464 changed both to str.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JelleZijlstra JelleZijlstra merged commit 0a67605 into PyCQA:master Jan 10, 2022
@Akuli Akuli deleted the union-check branch January 10, 2022 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants