Skip to content

strptime exception context #61772

Closed
Closed

Description

@PCManticore
BPO 17572
Nosy @ezio-melotti, @PCManticore
Files
  • strptime.patch
  • issue17572.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/ezio-melotti'
    closed_at = <Date 2013-04-03.23:17:26.376>
    created_at = <Date 2013-03-29.10:48:03.948>
    labels = ['type-bug', 'library']
    title = 'strptime exception context'
    updated_at = <Date 2013-04-03.23:17:26.375>
    user = 'https://github.com/PCManticore'

    bugs.python.org fields:

    activity = <Date 2013-04-03.23:17:26.375>
    actor = 'ezio.melotti'
    assignee = 'ezio.melotti'
    closed = True
    closed_date = <Date 2013-04-03.23:17:26.376>
    closer = 'ezio.melotti'
    components = ['Library (Lib)']
    creation = <Date 2013-03-29.10:48:03.948>
    creator = 'Claudiu.Popa'
    dependencies = []
    files = ['29602', '29605']
    hgrepos = []
    issue_num = 17572
    keywords = ['patch']
    message_count = 4.0
    messages = ['185495', '185520', '185976', '185977']
    nosy_count = 3.0
    nosy_names = ['ezio.melotti', 'Claudiu.Popa', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue17572'
    versions = ['Python 3.3', 'Python 3.4']

    Activity

    1. PCManticore commented on Mar 29, 2013

      PCManticoremannequin
      MannequinAuthor

      When using a directive that is not recognised by time.strptime, the following occurs in Python 3:

      >>> time.strptime("", "%D")
      Traceback (most recent call last):
        File "C:\Python33\lib\_strptime.py", line 320, in _strptime
          format_regex = _TimeRE_cache.compile(format)
        File "C:\Python33\lib\_strptime.py", line 268, in compile
          return re_compile(self.pattern(format), IGNORECASE)
        File "C:\Python33\lib\_strptime.py", line 262, in pattern
          self[format[directive_index]])
      KeyError: 'D'
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "C:\Python33\lib\_strptime.py", line 494, in _strptime_time
          tt = _strptime(data_string, format)[0]
        File "C:\Python33\lib\_strptime.py", line 329, in _strptime
          (bad_directive, format))
      ValueError: 'D' is a bad directive in format '%D'
      >>>

      Probably the KeyError should be supressed when raising the ValueError. The attached patch tries to fix this issue, by suppressing the context.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Mar 29, 2013
    3. ezio-melotti commented on Mar 29, 2013

      @ezio-melotti
      Member

      The fix LGTM. The attached patch tweaks a bit your test and adds another one to check _strptime directly.

    4. python-dev commented on Apr 3, 2013

      python-devmannequin
      Mannequin

      New changeset 3203e083aa7b by Ezio Melotti in branch '3.3':
      bpo-17572: Avoid chained exceptions while passing bad directives to time.strptime(). Initial patch by Claudiu Popa.
      http://hg.python.org/cpython/rev/3203e083aa7b

      New changeset d408c9bd4bf7 by Ezio Melotti in branch 'default':
      bpo-17572: merge with 3.3.
      http://hg.python.org/cpython/rev/d408c9bd4bf7

    5. ezio-melotti commented on Apr 3, 2013

      @ezio-melotti
      Member

      Fixed, thanks for the report and the patch!

    6. self-assigned this
      on Apr 3, 2013
    7. transferred this issue fromon Apr 10, 2022
    8. added 3 commits that reference this issue on Nov 12, 2026
    9. added a commit that references this issue on Nov 12, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions