Skip to content
Prev Previous commit
Next Next commit
Fix the stacklevel and remove example from the warning message.
  • Loading branch information
gpshead committed Mar 20, 2024
commit b0eacf9db3bf7e6cb1a1d7e4db1068f3402c967e
6 changes: 2 additions & 4 deletions Lib/_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,10 @@ def pattern(self, format):
Parsing dates involving a day of month without a year specified is ambiguious
and fails to parse leap day. The default behavior will change in Python 3.15
to either always raise an exception or to use a different default year (TBD).
To avoid trouble, add a specific year to the input & format. For example:
strptime(f"{mm_dd},{datetime.now().year}", "%m-%d,%y")
To avoid trouble, add a specific year to the input & format.
See https://github.com/python/cpython/issues/70647.""",
DeprecationWarning,
# -> .compile -> {time,datetime}.strptime -> User
stacklevel=3)
stacklevel=5)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The 5 looks fragile, but I don't see a good way around it, short of teaching warnings new tricks.
Hopefully this code won't get refactored in the next few years.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, wow, nice job with the time machine :)

Suggested change
stacklevel=5)
skip_file_prefixes=(os.path.dirname(__file__),))

Looks like this would be the first use of skip_file_prefixes in the stdlib.

return "%s%s" % (processed_format, format)

def compile(self, format):
Expand Down