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

The tempfile._infer_return_type function cannot infer the type of os.PathLike objects. #89355

Open
rekyungmin mannequin opened this issue Sep 14, 2021 · 7 comments
Open
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@rekyungmin
Copy link
Mannequin

rekyungmin mannequin commented Sep 14, 2021

BPO 45192
Nosy @ambv, @miss-islington, @akulakov, @rekyungmin
PRs
  • bpo-45192: Fix a bug that infers the type of an os.PathLike[bytes] object as str #28323
  • [3.10] bpo-45192: Fix a bug that infers the type of an os.PathLike[bytes] object as str (GH-28323) #29111
  • [3.9] bpo-45192: Fix a bug that infers the type of an os.PathLike[bytes] object as str (GH-28323) #29112
  • 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 = None
    closed_at = None
    created_at = <Date 2021-09-14.05:44:04.045>
    labels = ['type-bug', '3.8', '3.9', '3.10', '3.7', 'library']
    title = 'The tempfile._infer_return_type function cannot infer the type of os.PathLike objects.'
    updated_at = <Date 2021-10-20.21:27:38.952>
    user = 'https://github.com/rekyungmin'

    bugs.python.org fields:

    activity = <Date 2021-10-20.21:27:38.952>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2021-09-14.05:44:04.045>
    creator = 'rekyungmin'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45192
    keywords = ['patch']
    message_count = 6.0
    messages = ['401754', '401755', '404139', '404523', '404528', '404529']
    nosy_count = 4.0
    nosy_names = ['lukasz.langa', 'miss-islington', 'andrei.avk', 'rekyungmin']
    pr_nums = ['28323', '29111', '29112']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue45192'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10']

    @rekyungmin
    Copy link
    Mannequin Author

    rekyungmin mannequin commented Sep 14, 2021

    The tempfile module has been updated to accept an object implementing os.PathLike protocol for path-related parameters as of Python 3.6 (e.g. dir parameter). An os.PathLike object represents a filesystem path as a str or bytes object (i.e. def __fspath__(self) -> Union[str, bytes]:). However, if an object implementing os.PathLike[bytes] is passed as a dir argument, a TypeError is raised. This bug occurs because the tempfile._infer_return_type function considers all objects other than bytes as str type.

    @rekyungmin rekyungmin mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Sep 14, 2021
    @rekyungmin
    Copy link
    Mannequin Author

    rekyungmin mannequin commented Sep 14, 2021

    for example:
    
    from typing import Union
    
    
    class FakePath:
        def __init__(self, path):
            self.path = path
    
        def __fspath__(self) -> Union[str, bytes]:
            return self.path
    
    
    if __name__ == "__main__":
        from tempfile import TemporaryDirectory
    
        # You need to create `existing_path` directory
    
        with TemporaryDirectory(dir=FakePath("existing_path")) as str_path:
            print(str_path)  # 'existing_path/...'
    
        with TemporaryDirectory(dir=FakePath(b"existing_path")) as byte_path:
            print(byte_path)  # expected b'existing_path/...' but raised TypeError
    
    

    @akulakov
    Copy link
    Contributor

    This is a duplicate of bpo-29447, so if this is merged, the other issue should also be closed as fixed.

    @ambv
    Copy link
    Contributor

    ambv commented Oct 20, 2021

    New changeset 6270d3e by Kyungmin Lee in branch 'main':
    bpo-45192: Fix a bug that infers the type of an os.PathLike[bytes] object as str (GH-28323)
    6270d3e

    @ambv
    Copy link
    Contributor

    ambv commented Oct 20, 2021

    New changeset d33fae7 by Miss Islington (bot) in branch '3.9':
    bpo-45192: Fix a bug that infers the type of an os.PathLike[bytes] object as str (GH-28323) (GH-29112)
    d33fae7

    @ambv
    Copy link
    Contributor

    ambv commented Oct 20, 2021

    New changeset 64e83c7 by Miss Islington (bot) in branch '3.10':
    bpo-45192: Fix a bug that infers the type of an os.PathLike[bytes] object as str (GH-28323) (GH-29111)
    64e83c7

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @furkanonder
    Copy link
    Sponsor Contributor

    @ambv Issue seems to resolved. We can close the issue.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    Status: No status
    Development

    No branches or pull requests

    3 participants