Skip to content

Add stub for filecmp to 2and3 #955

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 5 commits into from
Mar 8, 2017
Merged

Conversation

euresti
Copy link
Contributor

@euresti euresti commented Feb 24, 2017

No description provided.

import sys
from typing import AnyStr, Callable, Dict, Generic, Iterable, List, Optional, Sequence, Tuple

_SupportsBool = object
Copy link
Member

Choose a reason for hiding this comment

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

Seems fine to just use bool as the type for the shallow argument to cmp. From looking at the code it does technically support any object that implements __bool__ (which is all objects), but many existing stubs use bool for arguments that don't strictly need to be bools.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did this because the default value is 1 in python2 and True on python3 I didn't want people who used 0 to suddenly fail. If that's not a problem I can switch it to bool or I can make it Union[int, bool] if you think it's important.

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense, I shouldn't have checked just the Python 3 code. :)

bool is a subtype of int, so maybe we could just use int, but I don't feel strongly about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made it a Union[int, bool] since that's how people should probably call it with.


DEFAULT_IGNORES = ... # type: List[str]

def cmp(f1: AnyStr, f2: AnyStr, shallow: _SupportsBool = ...) -> bool: ...
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure AnyStr is correct here. Jukka has some draft guidance in #871, which says that AnyStr should be used only when there are multiple arguments that must be of the same type. I don't think that's the case here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe I tested this manually and found that mixing str and bytes was bad in python3. I'll test again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually it's fine in python3 to mix bytes and str so I changed it to Union[bytes, Text]

def phase3(self) -> None: ...
def phase4(self) -> None: ...
def phase4_closure(self) -> None: ...
def report(self) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

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

These three are documented, so I don't think they belong in the "These should probably be private" section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll just remove the comment. It's not for me to comment on how the stdlib is implemented. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved stuff around.

@matthiaskramm matthiaskramm merged commit a1e74b9 into python:master Mar 8, 2017
@euresti euresti deleted the filecmp branch March 8, 2017 19:37
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