Skip to content

Introduce _typeshed.Maybe #7870

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

Closed
wants to merge 2 commits into from
Closed

Introduce _typeshed.Maybe #7870

wants to merge 2 commits into from

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented May 18, 2022

We use the X | Any pattern for return types more and more. Introducing a type alias legitimizes the pattern, makes it easier to recognize, easier to grep, and means that we don't need to repeat the documentation.

@github-actions

This comment has been minimized.

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 getting rid of the comment copy/pasta.

I'm not sure if Maybe is a good name for this, since it means "could be None and you must check for it" in some other languages, but I don't have better suggestions in mind.

Co-authored-by: Akuli <[email protected]>
@srittau
Copy link
Collaborator Author

srittau commented May 18, 2022

I'm not sure if Maybe is a good name for this, since it means "could be None and you must check for it" in some other languages, but I don't have better suggestions in mind.

True, but it's succinct and has the meaning "could be unset/null/none/undefined" in other languages, so the name at least has some meaning, even if it's not a 100% match to what other languages do.

@hauntsaninja
Copy link
Collaborator

We've talked about WeakUnion before, so WeakOptional seems a pretty natural name to me

@github-actions
Copy link
Contributor

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

@srittau
Copy link
Collaborator Author

srittau commented May 18, 2022

I don't think we should use "optional". That name has caused lots of confusion in the past. Also, it's a fairly long name.

@Akuli
Copy link
Collaborator

Akuli commented May 18, 2022

RarelyNone?

@JelleZijlstra
Copy link
Member

Probably? re.match probably returns a match, so it returns Probably[Match[str]].

@srittau
Copy link
Collaborator Author

srittau commented May 19, 2022

We could bikeshed this forever, but I still think Maybe is the best option.

@AlexWaygood
Copy link
Member

We could bikeshed this forever

Indeed we could, but I do think the choice of name is important here -- I'd prefer the status quo over a confusing alias name. Personally, I prefer either Probably or RarelyNone to Maybe 🙂

@srittau
Copy link
Collaborator Author

srittau commented May 19, 2022

Probably and RarelyNone suggest that None is somehow the less common case. That's not true in many cases, for example Match.group() with optional groups.

@AlexWaygood
Copy link
Member

AlexWaygood commented May 19, 2022

Often? That has less of an implication that the result is necessarily the majority of cases, compared to Probably or RarelyNone.

@Akuli
Copy link
Collaborator

Akuli commented May 19, 2022

I think the name shouldn't be too clever or short. If you see Often in the middle of some code, how are you supposed to know that it has something to do with unions and None, let alone guess its meaning?

Maybe we should just call this TheAnyTrick. It's very obvious for typeshed maintainers. It isn't obvious at first for people new to typing, but this is a difficult concept, and I don't think we can make it guessable anyway.

@AlexWaygood
Copy link
Member

AlexWaygood commented May 25, 2022

Maybe we should just call this TheAnyTrick. It's very obvious for typeshed maintainers. It isn't obvious at first for people new to typing, but this is a difficult concept, and I don't think we can make it guessable anyway.

I'd be fine with AnyTrick or TheAnyTrick. I agree it's better to have an opaque name than a name that's too clever or succinct.

@srittau
Copy link
Collaborator Author

srittau commented May 25, 2022

No consensus.

@srittau srittau closed this May 25, 2022
@srittau srittau deleted the maybe branch August 14, 2023 15:26
@Akuli Akuli mentioned this pull request Dec 1, 2023
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.

5 participants