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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/3/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class statvfs_result: # Unix only
# ----- os function stubs -----
def fsencode(filename: str) -> bytes: ...
def fsdecode(filename: bytes) -> str: ...
def get_exec_path(env: Optional[Dict[str, str]] = ...) -> List[str] : ...
def get_exec_path(env: Optional[Mapping[str, str]] = ...) -> List[str] : ...
# NOTE: get_exec_path(): returns List[bytes] when env not None
def ctermid() -> str: ... # Unix only
def getegid() -> int: ... # Unix only
Expand Down
4 changes: 2 additions & 2 deletions stdlib/3/unittest.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ _FT = TypeVar('_FT', Callable[[Any], Any])


def skip(reason: str) -> Callable[[_FT], _FT]: ...
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.

def expectedFailure(func: _FT) -> _FT: ...

class SkipTest(Exception):
Expand Down