Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Two small changes to help the mypy test suite pass #355

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

Merged
merged 2 commits into from
Jul 12, 2016
Merged

Conversation

gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented Jul 12, 2016

This is an alternative to python/mypy#1841. @matthiaskramm What do you think?

def skipIf(condition: bool, reason: str) -> Callable[[_FT], _FT]: ...
def skipUnless(condition: bool, reason: str) -> Callable[[_FT], _FT]: ...
def skipIf(condition: object, reason: str) -> Callable[[_FT], _FT]: ...
def skipUnless(condition: object, reason: str) -> Callable[[_FT], _FT]: ...
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you just write

def skipIf(condition, reason: str) -> ...

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because this is a stub, there's really no difference between leaving the type out, using Any, or using object. I like object because the truthiness check is actually defined there (other objects just override it). But I'm flexible. What's your preference?

Copy link
Contributor

Choose a reason for hiding this comment

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

I usually prefer leaving the type out, but I see your point about __nonzero__ in this particular case.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to always write down a type in a stub when you know what it is, because otherwise it's not clear if the absence of a type is purposeful or if the stub is incomplete. If we left the type out here, for example, I could imagine someone in the future trying to change it back to bool, thinking it was accidentally left out.

Also, I'd strongly prefer object to Any in this case, even though they have the same effect: Any implies the use of an escape hatch is necessary/the function can't be properly typed, which isn't the case here.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ddfisher ddfisher merged commit 1c4662d into master Jul 12, 2016
@ddfisher ddfisher deleted the fix-mypy-sync branch July 12, 2016 21:10
hswong3i pushed a commit to alvistack/python-typeshed that referenced this pull request May 25, 2025
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.

3 participants