Skip to content

Conversation

@PythonCoderAS
Copy link
Contributor

Fix #9578

Confirmed the methods changed do not have the weird behavior as seen in versions prior to Python 3.8 via testing.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Confirmed the methods changed do not have the weird behavior as seen in versions prior to Python 3.8 via testing.

The change is correct on Python 3.7 also (typeshed still supports 3.7):

(py37) C:\Users\alexw\coding>python
Python 3.7.16 (default, Jan 17 2023, 16:06:28) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> class Foo(datetime.datetime): ...
...
>>> Foo.combine(datetime.date(1999, 1, 1), datetime.time())
Foo(1999, 1, 1, 0, 0)
>>> type(_)
<class '__main__.Foo'>
>>> Foo.strptime("1999-1-1", "%Y-%m-%d")
Foo(1999, 1, 1, 0, 0)
>>> type(_)
<class '__main__.Foo'>

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pandas (https://github.com/pandas-dev/pandas)
+ pandas/_libs/tslibs/timestamps.pyi:138: error: Return type "datetime" of "strptime" incompatible with return type "Timestamp" in supertype "datetime"  [override]

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ pandas-stubs/_libs/tslibs/timestamps.pyi:151: error: Return type "datetime" of "strptime" incompatible with return type "Timestamp" in supertype "datetime"  [override]

@AlexWaygood AlexWaygood merged commit 52cf716 into python:main Feb 10, 2023
@PythonCoderAS PythonCoderAS deleted the patch-1 branch February 10, 2023 15:53
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.

Python's datetime.datetime.strptime has wrong return type

2 participants