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

pathlib.Path.__enter__() should emit DeprecationWarning #90714

Closed
barneygale mannequin opened this issue Jan 27, 2022 · 6 comments
Closed

pathlib.Path.__enter__() should emit DeprecationWarning #90714

barneygale mannequin opened this issue Jan 27, 2022 · 6 comments
Labels
3.11 only security fixes stdlib Python modules in the Lib dir topic-pathlib type-bug An unexpected behavior, bug, or error

Comments

@barneygale
Copy link
Mannequin

barneygale mannequin commented Jan 27, 2022

BPO 46556
Nosy @brettcannon, @barneygale
PRs
  • bpo-46556: emit DeprecationWarning from pathlib.Path.__enter__() #30971
  • 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 = <Date 2022-02-08.21:02:04.592>
    created_at = <Date 2022-01-27.23:07:21.767>
    labels = ['type-bug', 'library', '3.11']
    title = 'pathlib.Path.__enter__() should emit DeprecationWarning'
    updated_at = <Date 2022-02-08.21:02:04.592>
    user = 'https://github.com/barneygale'

    bugs.python.org fields:

    activity = <Date 2022-02-08.21:02:04.592>
    actor = 'brett.cannon'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-02-08.21:02:04.592>
    closer = 'brett.cannon'
    components = ['Library (Lib)']
    creation = <Date 2022-01-27.23:07:21.767>
    creator = 'barneygale'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46556
    keywords = ['patch']
    message_count = 2.0
    messages = ['411936', '412870']
    nosy_count = 2.0
    nosy_names = ['brett.cannon', 'barneygale']
    pr_nums = ['30971']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46556'
    versions = ['Python 3.11']

    @barneygale
    Copy link
    Mannequin Author

    barneygale mannequin commented Jan 27, 2022

    In Python 3.9 / bpo-39682 we made Path.__exit__() a no-op, and added a comment in the code mentioning that it should be deprecated in future. The future is here, so let's deprecate it.

    @barneygale barneygale mannequin added 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 27, 2022
    @brettcannon
    Copy link
    Member

    New changeset 06e1701 by Barney Gale in branch 'main':
    bpo-46556: emit DeprecationWarning from pathlib.Path.__enter__() (GH-30971)
    06e1701

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    skshetry added a commit to skshetry/hydra that referenced this issue Oct 15, 2022
    Path as a contextmanager is deprecated from 3.11 onwards, and was a
    no-op since Python 3.11. Also this functionality was never documented.
    
    See [cpython/Lib/pathlib.py#L810-L816][1], python/cpython#83863 and, python/cpython#90714.
    
    [1]: https://github.com/python/cpython/blob/120b4ab2b68aebf96ce0de243eab89a25fc2d282/Lib/pathlib.py#L810-L816
    skshetry added a commit to skshetry/hydra that referenced this issue Oct 15, 2022
    Path as a contextmanager is deprecated from 3.11 onwards, and was a
    no-op since Python 3.9. Also this functionality was never documented.
    
    See [cpython/Lib/pathlib.py#L810-L816][1], python/cpython#83863 and, python/cpython#90714.
    
    [1]: https://github.com/python/cpython/blob/120b4ab2b68aebf96ce0de243eab89a25fc2d282/Lib/pathlib.py#L810-L816
    pixelb pushed a commit to facebookresearch/hydra that referenced this issue Oct 17, 2022
    Path as a contextmanager is deprecated from 3.11 onwards, and was a
    no-op since Python 3.9. Also this functionality was never documented.
    
    See [cpython/Lib/pathlib.py#L810-L816][1], python/cpython#83863 and, python/cpython#90714.
    
    [1]: https://github.com/python/cpython/blob/120b4ab2b68aebf96ce0de243eab89a25fc2d282/Lib/pathlib.py#L810-L816
    @dss010101
    Copy link

    so how do we use Path to avoid this warning?

    @dss010101
    Copy link

    anyone..anyone...

    @barneygale
    Copy link
    Contributor

    so how do we use Path to avoid this warning?

    Don't use a path object as a context manager, e.g. rather than:

    with Path('foo') as path:
        ...

    use:

    path = Path('foo')

    @dss010101
    Copy link

    so how do we use Path to avoid this warning?

    Don't use a path object as a context manager, e.g. rather than:

    with Path('foo') as path:
        ...

    use:

    path = Path('foo')

    Ah got it. that is what i had ended up doing - wasn't sure if there still was a way to use it with the 'with' block.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes stdlib Python modules in the Lib dir topic-pathlib type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants