GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Path takes and ignores **kwargs · Issue #74033 · python/cpython

Path takes and ignores **kwargs #74033

New issue
Copy link
New issue
Copy link
Closed
Closed
Path takes and ignores **kwargs#74033
Copy link
Labels
3.10 (EOL)end of lifeend of life3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@JelleZijlstra
JelleZijlstra
opened on Mar 18, 2017
Issue body actions
BPO 29847
Nosy @brettcannon, @pitrou, @serhiy-storchaka, @jstasiak, @JelleZijlstra, @DimitrisJim, @remilapeyre, @uriyyo
PRs
  • bpo-29847: Path subclasses raise TypeError given kwargs #13399
  • gh-74033: Fix bug when Path takes and ignores **kwargs #19632
  • 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 2017-03-18.15:22:47.434>
    labels = ['type-bug', '3.8', '3.9', '3.10', '3.7', 'library']
    title = 'Path takes and ignores **kwargs'
    updated_at = <Date 2020-06-10.22:05:47.572>
    user = 'https://github.com/JelleZijlstra'

    bugs.python.org fields:

    activity = <Date 2020-06-10.22:05:47.572>
    actor = 'remi.lapeyre'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2017-03-18.15:22:47.434>
    creator = 'JelleZijlstra'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 29847
    keywords = ['patch']
    message_count = 9.0
    messages = ['289817', '289896', '289897', '289902', '289944', '289945', '289946', '289998', '369520']
    nosy_count = 8.0
    nosy_names = ['brett.cannon', 'pitrou', 'serhiy.storchaka', 'jstasiak', 'JelleZijlstra', 'Jim Fasarakis-Hilliard', 'remi.lapeyre', 'uriyyo']
    pr_nums = ['13399', '19632']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29847'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10']

    Linked PRs

    • GH-74033: Drop deprecated pathlib.Path keyword arguments #118793

    Activity

    1. JelleZijlstra commented on Mar 18, 2017

      @JelleZijlstra
      JelleZijlstra
      on Mar 18, 2017
      MemberAuthor
      More actions

      pathlib.Path.__new__ takes **kwargs, but doesn't do anything with them (https://github.com/python/cpython/blob/master/Lib/pathlib.py#L979). This doesn't appear to be documented.

      This feature should presumably be either documented or removed (probably removed unless I'm missing some reason for having it).

      Brief discussion on a typeshed PR at python/typeshed#991 (diff)

    2. brettcannon commented on Mar 20, 2017

      @brettcannon
      brettcannon
      on Mar 20, 2017
      Member
      More actions

      Yep, kwargs should be dropped since it isn't used or documented: https://docs.python.org/3/library/pathlib.html#pathlib.PurePath (probably just a hold-over from when it did in some earlier version of the code).

    3. brettcannon
      added
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      3.7 (EOL)end of lifeend of life
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Mar 20, 2017
    4. JelleZijlstra commented on Mar 20, 2017

      @JelleZijlstra
      JelleZijlstra
      on Mar 20, 2017
      MemberAuthor
      More actions

      Thanks, I'll add a PR. This doesn't need to be documented, right?

    5. serhiy-storchaka commented on Mar 20, 2017

      @serhiy-storchaka
      serhiy-storchaka
      on Mar 20, 2017
      Member
      More actions

      The support of **kwargs in Path.__new__ is needed if you want to implement a subclass of Path with __init__ accepting keyword arguments (and since Path constructor takes variable number of positional arguments, new arguments should be keyword-only).

      >>> import pathlib
      >>> class MyPath(pathlib.PosixPath):
      ...     def __init__(self, *args, spam=False):
      ...         self.spam = spam
      ... 
      >>> p = MyPath('/', spam=True)
      >>> p
      MyPath('/')
      >>> p.spam
      True

      Removing **kwargs from Path.__new__ will break the above example.

      >>> MyPath('/', spam=True)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: __new__() got an unexpected keyword argument 'spam'
    6. brettcannon commented on Mar 21, 2017

      @brettcannon
      brettcannon
      on Mar 21, 2017
      Member
      More actions

      Shoot, that's too bad. I guess we should document it then so people are aware that keyword arguments are ignored, else we will break subclasses. There's also an unfortunate difference between PurePath and Path as PurePath doesn't have this quirk.

    7. serhiy-storchaka commented on Mar 21, 2017

      @serhiy-storchaka
      serhiy-storchaka
      on Mar 21, 2017
      Member
      More actions

      I don't know whether it was the intension of Antoine or just an oversight. I don't know whether it is used in the wild. But we can at least raise a TypeError for concrete classes PosixPath and WindowsPath if ignoring keyword arguments is a problem. Many extension types don't take keyword arguments, but their subclasses accept and ignore keyword arguments. For example:

      >>> filter(None, [], foo=123)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: filter() does not take keyword arguments
      >>> class X(filter): pass
      ... 
      >>> X(None, [], foo=123)
      <__main__.X object at 0xb6fdcacc>
    8. pitrou commented on Mar 21, 2017

      @pitrou
      pitrou
      on Mar 21, 2017
      Member
      More actions

      The support of **kwargs in Path.__new__ is needed if you want to implement a subclass of Path with __init__ accepting keyword arguments

      I don't remember exactly, but I think this was the intention indeed. There was originally an openat-using subclass, and IIRC it took additional parameters (such as the directory fd). That got scrapped quite early in the process, so we can remove the **kwargs thing now.

    9. brettcannon commented on Mar 22, 2017

      @brettcannon
      brettcannon
      on Mar 22, 2017
      Member
      More actions

      Then I vote for Serhiy's idea of simply raising an exception in the concrete subclasses when a keyword argument is given.

    10. remilapeyre commented on May 21, 2020

      @remilapeyre
      remilapeyremannequin
      on May 21, 2020
      Mannequin
      More actions

      PurePath subclasses cannot support kwargs as __new__() does not accept **kwargs:

      >>> from pathlib import PurePath
      >>> class MyPurePath(PurePath):
      ...     def __init__(self, *args, **kargs): pass
      ... 
      >>> MyPurePath('foo', spam=True)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: __new__() got an unexpected keyword argument 'spam'

      The behaviour for this should probably be made the same for both Path and PurePath.

    11. remilapeyre
      added
      3.8 (EOL)end of lifeend of life
      3.9 (EOL)end of lifeend of life
      3.10 (EOL)end of lifeend of life
      on Jun 10, 2020
    12. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    13. jaraco commented on Oct 10, 2022

      @jaraco
      jaraco
      on Oct 10, 2022
      Member
      More actions

      As reported in the dupe bug, this bug led to masking a user mistake.

    14. brettcannon
      added
      topic-pathlib
      on Oct 14, 2022
    15. barneygale commented on Jan 5, 2023

      @barneygale
      barneygale
      on Jan 5, 2023
      Contributor
      More actions

      #100481 would fix this without breaking subclassing by adding an __init__() method.

    16. miss-islington
      added a commit that references this issue on Jan 14, 2023

      gh-74033: Fix bug when Path takes and ignores **kwargs (GH-19632)

      080cb27
    17. brettcannon commented on Jan 14, 2023

      @brettcannon
      brettcannon
      on Jan 14, 2023
      Member
      More actions

      I took #19632 as a fix, but it can obviously be tweaked as long as the deprecation warning sticks around.

    18. brettcannon
      closed this as completedon Jan 14, 2023
    19. barneygale
      added 5 commits that reference this issue on May 8, 2024

      pythonGH-74033: Drop deprecated `pathlib.Path()` keyword arguments

      2468f33

      Merge branch 'main' into pythongh-74033-remove

      85eb732

      Merge branch 'main' into pythongh-74033-remove

      92cbfd0

      Merge branch 'main' into pythongh-74033-remove

      36bb885

      GH-74033: Drop deprecated `pathlib.Path` keyword arguments (#118793)

      7d8725a
    20. estyxx
      added a commit that references this issue on Jul 17, 2024

      pythonGH-74033: Drop deprecated `pathlib.Path` keyword arguments (pyt…

      3fee9e3
    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

      3.10 (EOL)end of lifeend of life3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        You are visitor 01402503 — GeezerVison does not store the pages you look up.
        Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.