Skip to content

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

Merged
ddfisher merged 2 commits into
masterfrom
fix-mypy-sync
Jul 12, 2016
Merged

Two small changes to help the mypy test suite pass#355
ddfisher merged 2 commits into
masterfrom
fix-mypy-sync

Conversation

@gvanrossum

@gvanrossum gvanrossum commented Jul 12, 2016

Copy link
Copy Markdown
Member

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

Comment thread stdlib/3/unittest.pyi
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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