Skip to content
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

time.strptime should reject bytes arguments on Py3 #49486

Closed
ezio-melotti opened this issue Feb 12, 2009 · 10 comments
Closed

time.strptime should reject bytes arguments on Py3 #49486

ezio-melotti opened this issue Feb 12, 2009 · 10 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@ezio-melotti
Copy link
Member

BPO 5236
Nosy @brettcannon, @amauryfa, @ezio-melotti
Files
  • strptime_patch.txt
  • strptime_patch_v2.txt
  • 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/brettcannon'
    closed_at = <Date 2009-03-30.21:31:25.266>
    created_at = <Date 2009-02-12.22:50:32.729>
    labels = ['type-bug', 'library']
    title = 'time.strptime should reject bytes arguments on Py3'
    updated_at = <Date 2009-03-30.21:31:25.264>
    user = 'https://github.com/ezio-melotti'

    bugs.python.org fields:

    activity = <Date 2009-03-30.21:31:25.264>
    actor = 'brett.cannon'
    assignee = 'brett.cannon'
    closed = True
    closed_date = <Date 2009-03-30.21:31:25.266>
    closer = 'brett.cannon'
    components = ['Library (Lib)']
    creation = <Date 2009-02-12.22:50:32.729>
    creator = 'ezio.melotti'
    dependencies = []
    files = ['13311', '13355']
    hgrepos = []
    issue_num = 5236
    keywords = []
    message_count = 10.0
    messages = ['81834', '83485', '83486', '83487', '83488', '83506', '83701', '83702', '84643', '84655']
    nosy_count = 4.0
    nosy_names = ['brett.cannon', 'amaury.forgeotdarc', 'ezio.melotti', 'tleeuwenburg@gmail.com']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue5236'
    versions = ['Python 3.1']

    @ezio-melotti
    Copy link
    Member Author

    On Python3 time.strptime(string[, format]) accepts bytes as arguments
    and then fails:

    >>> strptime(b"2009", "%Y")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Programs\Python30\lib\_strptime.py", line 454, in _strptime_time
        return _strptime(data_string, format)[0]
      File "C:\Programs\Python30\lib\_strptime.py", line 322, in _strptime
        found = format_regex.match(data_string)
    TypeError: can't use a string pattern on a bytes-like object
    
    time.strftime already rejects bytes arguments:
    >>> strftime(b'%Y')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: strftime() argument 1 must be str, not bytes

    time.strptime should do the same and reject bytes for both the arguments
    (string and format).

    (With Py2.x both str and unicode args work.)

    @ezio-melotti ezio-melotti added stdlib Python modules in the Lib dir topic-unicode type-bug An unexpected behavior, bug, or error labels Feb 12, 2009
    @brettcannon brettcannon self-assigned this Feb 13, 2009
    @tleeuwenburggmailcom
    Copy link
    Mannequin

    tleeuwenburggmailcom mannequin commented Mar 12, 2009

    I believe this shouldn't be tagged as part of the Lib component...

    Also, I am happy to work on this issue, developing tests and a patch.
    Would that be appropriate? I may take a little while to get the hang of
    things, but I'm happy to put some time into this.

    @tleeuwenburggmailcom tleeuwenburggmailcom mannequin added extension-modules C modules in the Modules dir and removed stdlib Python modules in the Lib dir topic-unicode labels Mar 12, 2009
    @tleeuwenburggmailcom
    Copy link
    Mannequin

    tleeuwenburggmailcom mannequin commented Mar 12, 2009

    My mistake, it is part of the Lib component ... I failed to see the
    callback to Python from timemodule.c and jumped to conclusions.

    In any case, I'm happy to work on this.

    @tleeuwenburggmailcom
    Copy link
    Mannequin

    tleeuwenburggmailcom mannequin commented Mar 12, 2009

    @brettcannon
    Copy link
    Member

    If you want to work on it, Tennesse, then go for it!

    @brettcannon brettcannon added stdlib Python modules in the Lib dir and removed extension-modules C modules in the Modules dir labels Mar 12, 2009
    @tleeuwenburggmailcom
    Copy link
    Mannequin

    tleeuwenburggmailcom mannequin commented Mar 12, 2009

    Python implementation to raise this exception if a bytes argument is
    passed in as argument 1.

    Test case added to test_time

    @amauryfa
    Copy link
    Member

    Please remove the whitespace changes in the patch
    (around "_cache_lock"). Otherwise it is good.

    @tleeuwenburggmailcom
    Copy link
    Mannequin

    tleeuwenburggmailcom mannequin commented Mar 17, 2009

    Thanks for the comments all and sorry for the delay -- life!

    @brettcannon
    Copy link
    Member

    I am going to do a review at http://codereview.appspot.com/28147 ; not
    done yet.

    @brettcannon
    Copy link
    Member

    Applied in r70755 for py3k. I am not backporting as I changed it to
    explicitly check both arguments which is a change in semantics.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants