-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix datetime.strftime #6317
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
Fix datetime.strftime #6317
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
strftime(fmt: str) -> strftime(format: str)
- Loading branch information
commit c855b8f971c1993514a48e7605d19cc1a2961e79
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -55,7 +55,7 @@ class date: | |||||
@property | ||||||
def day(self) -> int: ... | ||||||
def ctime(self) -> str: ... | ||||||
def strftime(self, fmt: str) -> str: ... | ||||||
def strftime(self, format: str) -> str: ... | ||||||
def __format__(self, fmt: str) -> str: ... | ||||||
def isoformat(self) -> str: ... | ||||||
def timetuple(self) -> struct_time: ... | ||||||
|
@@ -118,7 +118,7 @@ class time: | |||||
if sys.version_info >= (3, 7): | ||||||
@classmethod | ||||||
def fromisoformat(cls: Type[_S], time_string: str) -> _S: ... | ||||||
def strftime(self, fmt: str) -> str: ... | ||||||
def strftime(self, format: str) -> str: ... | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
def __format__(self, fmt: str) -> str: ... | ||||||
def utcoffset(self) -> timedelta | None: ... | ||||||
def tzname(self) -> str | None: ... | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make it positional-only as discussed.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quoting https://bugs.python.org/msg373421, specifically:
What do you have against this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type checking is all about warning users about situations where their code could lead to unexpected errors. Passing a keyword argument to this parameter will currently cause code to raise an error sometimes (but not all the time, or even most of the time), as not all systems can be guaranteed to use the C implementation of
datetime
(this is partly why the Python implementation exists alongside the C implementation). If a user passes a positional argument to this parameter, however, then there is no possibility of an error. So, it seems correct that, as the situation currently stands, a type-checker should raise an error if a keyword argument is passed to this parameter, as doing so could in some situations lead to unexpected errors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's definitely better than the current situation to have the parameter named
format
, but I agree that the best option for now is to have it as a positional-only parameter in the stub.