Skip to content

test_strptime raises a DeprecationWarning #117655

Description

@Eclips4

Bug report

Bug description:

./python -m test -v test_strptime
== CPython 3.13.0a5+ (heads/main:ac45766673, Apr 8 2024, 23:14:32) [GCC 9.4.0]
== Linux-5.10.16.3-microsoft-standard-WSL2-x86_64-with-glibc2.31 little-endian
== Python build: debug
== cwd: /home/eclips4/CLionProjects/cpython/build/test_python_worker_28987æ
== CPU count: 16
== encodings: locale=UTF-8 FS=utf-8
== resources: all test resources are disabled, use -u option to unskip tests

Using random seed: 3103978630
0:00:00 load avg: 29.90 Run 1 test sequentially
0:00:00 load avg: 29.90 [1/1] test_strptime
test_TimeRE_recreation_locale (test.test_strptime.CacheTests.test_TimeRE_recreation_locale) ... sys:1: DeprecationWarning: 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.
See https://github.com/python/cpython/issues/70647.
skipped 'test needs de_DE.UTF8 locale'

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    testsTests in the Lib/test dir
    on Apr 8, 2024
  2. nineteendo commented on Apr 9, 2024

    @nineteendo
    Contributor

    So, we just need to do this? Can I make a pull request for that?

    -_strptime._strptime_time("10", "%d")
    +_strptime._strptime_time("10 2004", "%d %Y")
  3. Eclips4 commented on Apr 9, 2024

    @Eclips4
    MemberAuthor

    Yes, that's looks good to me. I'm dislike the approach of catching DeprecationWarning because in future versions it can raise an exception.

  4. Eclips4 commented on Apr 9, 2024

    @Eclips4
    MemberAuthor

    However, there's also a similar warning in the test_datetime:

    ./python.exe -m test -q test_datetime
    Using random seed: 2525252452
    0:00:00 load avg: 41.62 Run 1 test sequentially
    sys:1: DeprecationWarning: 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.
    See https://github.com/python/cpython/issues/70647.
    sys:1: DeprecationWarning: 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.
    See https://github.com/python/cpython/issues/70647.
    sys:1: DeprecationWarning: 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.
    See https://github.com/python/cpython/issues/70647.
    sys:1: DeprecationWarning: 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.
    See https://github.com/python/cpython/issues/70647.
    sys:1: DeprecationWarning: 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.
    See https://github.com/python/cpython/issues/70647.
    sys:1: DeprecationWarning: 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.
    See https://github.com/python/cpython/issues/70647.
    
    == Tests result: SUCCESS ==
    
    Total duration: 3.6 sec
    Total tests: run=1,012 skipped=28
    Total test files: run=1/1
    Result: SUCCESS
  5. nineteendo commented on Apr 9, 2024

    @nineteendo
    Contributor

    That's caused by the tests of #70647 (resolved):

    def test_strptime_leap_year(self):
    # GH-70647: warns if parsing a format with a day and no year.
    with self.assertRaises(ValueError):
    # The existing behavior that GH-70647 seeks to change.
    self.theclass.strptime('02-29', '%m-%d')
    with self.assertWarnsRegex(DeprecationWarning,
    r'.*day of month without a year.*'):
    self.theclass.strptime('03-14.159265', '%m-%d.%f')
    with self._assertNotWarns(DeprecationWarning):
    self.theclass.strptime('20-03-14.159265', '%y-%m-%d.%f')
    with self._assertNotWarns(DeprecationWarning):
    self.theclass.strptime('02-29,2024', '%m-%d,%Y')

  6. nineteendo commented on Apr 9, 2024

    @nineteendo
    Contributor

    And we also have these tests that will still raise a DeprecationWarning (resolved):

    def test_feb29_on_leap_year_without_year(self):
    time.strptime("Feb 29", "%b %d")
    def test_mar1_comes_after_feb29_even_when_omitting_the_year(self):
    self.assertLess(
    time.strptime("Feb 29", "%b %d"),
    time.strptime("Mar 1", "%b %d"))

    Those will have to be removed in 3.15.

  7. erlend-aasland commented on Apr 9, 2024

    @erlend-aasland
    Contributor

    See commit 33ee5cb. Please follow the existing practice for how to deal with deprecation warnings in tests. See Greg's commit for inspiration. There also test.support.warnings_helper.ignore_warnings1.

    Footnotes

    1. git grep ignore_warnings Lib/test for inspiration. ↩

  8. nineteendo commented on Apr 9, 2024

    @nineteendo
    Contributor

    Yeah, test.support.warnings_helper.ignore_warnings() works here. (It even works on tests checking for deprecation warnings).
    I've added it to the functions were necessary, and updated the others to not use the deprecated behaviour.

  9. nineteendo commented on May 9, 2024

    @nineteendo
    Contributor

    Could someone review my pull request? I've waited exactly one month. In a week I'll ask on Discourse.

  10. nineteendo commented on May 9, 2024

    @nineteendo
    Contributor

    @Eclips4 can you review this, or should I ask on Discourse right away? erlend-aasland said he's not going to review this.

  11. Eclips4 commented on May 9, 2024

    @Eclips4
    MemberAuthor

    @Eclips4 can you review this, or should I ask on Discourse right away? erlend-aasland said he's not going to review this.

    Will do it later today. Please note that before merging, we should also get a review from Greg or Paul.

  12. nineteendo commented on May 9, 2024

    @nineteendo
    Contributor

    Even after waiting one month? But if they decide to review it now, that would be appreciated.

  13. added a commit that references this issue on May 11, 2024
  14. gpshead commented on May 11, 2024

    @gpshead
    Member

    thanks for the PR & pings. merged! =)

    cpython workflow wise... IIRC we don't have anything in our CI or buildbots treating warnings emitted by the test suite as a hard error so it they can be easily overlooked. I should've tried to do this with my original PR.

    There could be an argument made that test coverage of some code paths without the year specified is important to retain, but I believe we've got enough other explicit intentional tests for that behavior already so this issues PR change still the best way forward.

  15. added a commit that references this issue on May 11, 2024
  16. added a commit that references this issue on May 11, 2024
  17. added a commit that references this issue on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions