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 _typeshed.MaybeNone as Any trick marker #11815

Merged
merged 2 commits into from
Apr 23, 2024
Merged

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented Apr 23, 2024

Also condense the explanation in CONTRIBUTING to what's actionable for the user.

And mark Incomplete and Unused as stable.

Closes: #11094

Also condense the explanation in CONTRIBUTING to what's actionable for the user.

Closes: python#11094
@srittau
Copy link
Collaborator Author

srittau commented Apr 23, 2024

Cc @Avasam

This comment has been minimized.

# Marker for return types that include None, but where forcing the user to
# check for None can be detrimental. Sometimes called "the Any trick". See
# CONTRIBUTING.md for more information.
MaybeNone: TypeAlias = Any # stable
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
MaybeNone: TypeAlias = Any # stable
MaybeNone: TypeAlias = Any

This probably shouldn't be marked as stable yet, considering the import will fail in third party stubs until type checkers update their embedded version of typeshed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Stable is more meant as "We assure you that we won't remove this within the next year, at least."

@Avasam
Copy link
Sponsor Collaborator

Avasam commented Apr 23, 2024

I'm all for condensing the actionable part of documentation. I'm a little bit hesitant to make the call on the documentation changes, but I do think that you managed to nicely condense the information needed.

CC @Akuli as well as it was mainly their explanations.

If we close #11094 with this (which does satisfy the "documentation" part), we should also remember to actually review current | Any annotations, which I do want to do at some point, if no one else beats me to it.

Copy link
Collaborator

@Akuli Akuli left a comment

Choose a reason for hiding this comment

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

I like the concise explanation.

I have mixed feelings about the alias. On the one hand, it's "non-standard" and unnecessary from a technical point of view, but on the other hand, it's easier to guess the meaning of Foo | MaybeNone than Foo | Any. Overall I think it's worth trying.

CONTRIBUTING.md Outdated Show resolved Hide resolved
Co-authored-by: Akuli <akuviljanen17@gmail.com>
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@Avasam Avasam merged commit 7ed91bc into python:main Apr 23, 2024
54 checks passed
@srittau srittau deleted the maybe-none branch April 23, 2024 21:34
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.

Documenting the Any trick
4 participants