Skip to content

Introduce Y041: ban redundant numeric unions#222

Merged
AlexWaygood merged 9 commits intoPyCQA:masterfrom
AlexWaygood:intfloat
May 21, 2022
Merged

Introduce Y041: ban redundant numeric unions#222
AlexWaygood merged 9 commits intoPyCQA:masterfrom
AlexWaygood:intfloat

Conversation

@AlexWaygood
Copy link
Copy Markdown
Collaborator

No description provided.

@AlexWaygood
Copy link
Copy Markdown
Collaborator Author

I'll wait for reviews before doing a typeshed PR :)

@AlexWaygood AlexWaygood requested a review from JelleZijlstra May 21, 2022 09:54
Copy link
Copy Markdown
Member

@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, but see my (optional) comment regarding the early breakout.

@AlexWaygood
Copy link
Copy Markdown
Collaborator Author

AlexWaygood commented May 21, 2022

What should we do for type aliases like this, in fractions.pyi?

_ComparableNum: TypeAlias = int | float | Decimal | Real

Strictly speaking we can "simplify" this union to float | Decimal | Real. But it's more explicit and clear as it is, imo. Should we exempt type aliases from this check?

https://github.com/python/typeshed/blob/7576805aee96fe091821d4c963c46645a1894052/stdlib/fractions.pyi#L8

@AlexWaygood AlexWaygood changed the title Introduce Y041: ban redundant numeric unions Introduce Y041 & Y042: ban redundant numeric unions May 21, 2022
@srittau
Copy link
Copy Markdown
Member

srittau commented May 21, 2022

I would maybe even consider to exempt return types. -> int | float, while redundant, makes it clear that not all values returned must be floats, a distinction that is meaningless for argument types. But I have no strong feelings either way.

@AlexWaygood AlexWaygood changed the title Introduce Y041 & Y042: ban redundant numeric unions Introduce Y041: ban redundant numeric unions May 21, 2022
AlexWaygood added a commit to python/typeshed that referenced this pull request May 21, 2022
@AlexWaygood AlexWaygood reopened this May 21, 2022
@AlexWaygood AlexWaygood merged commit 99afc2a into PyCQA:master May 21, 2022
@AlexWaygood AlexWaygood deleted the intfloat branch May 21, 2022 14:42
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.

4 participants