8000 Issue 88: Stub for calendar module by lbolla · Pull Request #90 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Issue 88: St 8000 ub for calendar module #90

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 4 commits into from
Feb 25, 2016

Conversation

lbolla
Copy link
Contributor
@lbolla lbolla commented Feb 24, 2016

I created the stub using make_stub_files.py and then edited the types by hand.
I ran into an issue with mypy: it complains that True and False are not defined. Therefore, I had to define them in the stub.
Also, python runtests.py shows lots of errors: I don't know if this is expected.

@matthiaskramm
Copy link
Contributor

Rather than writing

withyear:bool=True

please write

withyear:bool=...

Same with None.

That way, you also don't run into the missing True/False mypy issue.

@gvanrossum
Copy link
Member

FWIW the issue of missing True/False is because of a recent change to builtin.pyi; there's a matching change needed to mypy but it has not landed yet (python/mypy#1218).

@JukkaL
Copy link
Contributor
JukkaL commented Feb 24, 2016

Note that if you have a None default value in code and use ... as the default in a stub, you should make the argument type Optional[...], as None is a valid argument value if the default is None.

@gvanrossum
Copy link
Member

Also PEP 8 and PEP 484 both say you should put spaces around the equal sign for a default when combined with a type. IOW instead of encoding: Optional[str]=None please write encoding: Optional[str] = None.

Use Optional[...] when appropriate.
Adhere to PEP-484 styling.
@lbolla
Copy link
Contributor Author
lbolla commented Feb 24, 2016

Thanks for your comments. I've amended the pull request with another commit.

YearType = int
MonthType = int
DayType = int
WeekdayType = int
Copy link
Member

Choose a reason for hiding this comment

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

Honestly I don't think these are very useful -- type checkers don't differentiate between them and the way it's written here these names are exported by the stub (but not by the real module). They just lengthen the signatures.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I believe that they provide useful information about what the module's functions do, though. For example, by looking at the signature of a method like itermonthdays2 one can immediately tell from the return type that the tuples are made of a day and a weekday (and not the other way around) without having to read the docs.

Copy link
Member

Choose a reason for hiding this comment

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

In general I want to resist seeing the type stubs as yet another form of docs. It should serve one need: to provide stubs usable by automatic type checkers. Also the majority of these are redundant, e.g. month: MonthType repeated over and over (in fact MonthType is less helpful than int!).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

De gustibus non est disputandum... I found them useful, but I am happy to remove them to adhere to the project's goals.

@lbolla
Copy link
Contributor Author
lbolla commented Feb 24, 2016

Good point. I've removed mention to the internal variables.

@gvanrossum
Copy link
Member

Thanks! All good now.

gvanrossum added a commit that referenced this pull request Feb 25, 2016
Issue 88: Stub for calendar module
@gvanrossum gvanrossum merged commit 2e7163f into python:master Feb 25, 2016
momandine pushed a commit to momandine/typeshed that referenced this pull request Jul 5, 2016
Allay fears about idiomatic python becoming far more verbose
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.

4 participants
0