Skip to content

add os.fspath() #71373

Closed
Closed

Description

@ethanfurman
BPO 27186
Nosy @brettcannon, @ethanfurman, @vadmium, @serhiy-storchaka, @JelleZijlstra, @buchuki, @erikjanss
Files
  • issue27186-fsencode.buchuki.patch
  • issue27186.patch: patch to add os.fspath and PyOS_FsPath
  • issue27186-DirEntry-fspath.patch: adds fspath support to os.DirEntry
  • issue27186-pathlib.buchuki.patch
  • issue27186-glossary.buchuki.patch: path-like glossary entry
  • issue27186-DirEntry-fspath.patch: patch to add fspath support to os.DirEntry
  • issue27186-os_path_t.patch: patch for the path_t converter in os
  • 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 2016-06-24.19:28:56.707>
    created_at = <Date 2016-06-02.18:22:21.760>
    labels = ['type-feature']
    title = 'add os.fspath()'
    updated_at = <Date 2018-08-13.23:04:39.687>
    user = 'https://github.com/ethanfurman'

    bugs.python.org fields:

    activity = <Date 2018-08-13.23:04:39.687>
    actor = 'erikjanss'
    assignee = 'brett.cannon'
    closed = True
    closed_date = <Date 2016-06-24.19:28:56.707>
    closer = 'brett.cannon'
    components = []
    creation = <Date 2016-06-02.18:22:21.760>
    creator = 'ethan.furman'
    dependencies = []
    files = ['43124', '43125', '43128', '43133', '43155', '43205', '43215']
    hgrepos = []
    issue_num = 27186
    keywords = ['patch']
    message_count = 45.0
    messages = ['266971', '266979', '266982', '266984', '267004', '267105', '267127', '267285', '267293', '267295', '267299', '267301', '267306', '267316', '267322', '267327', '267328', '267336', '267348', '267429', '267465', '268060', '268062', '268070', '268146', '268158', '268329', '268393', '268394', '268399', '268414', '268415', '268433', '268457', '268628', '269204', '269205', '269207', '269208', '269209', '269795', '269800', '323225', '323228', '323495']
    nosy_count = 8.0
    nosy_names = ['brett.cannon', 'ethan.furman', 'python-dev', 'martin.panter', 'serhiy.storchaka', 'JelleZijlstra', 'buchuki', 'erikjanss']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue27186'
    versions = ['Python 3.6']

    Activity

    1. python-dev commented on Jun 2, 2016

      python-devmannequin
      Mannequin

      New changeset 59a52a9dd0dc by Ethan Furman in branch 'default':
      bpo-27186 -- initial docs, tests, and python version of os.fspath
      https://hg.python.org/cpython/rev/59a52a9dd0dc

    2. buchuki commented on Jun 2, 2016

      buchukimannequin
      Mannequin

      Make os.fsencode and os.fsdecode able to accept a PathLike by calling into fspath. Additionally adds test for PathLike objects.

    3. buchuki commented on Jun 2, 2016

      buchukimannequin
      Mannequin

      Test __fspath__ returning bytes as well.

    4. JelleZijlstra commented on Jun 2, 2016

      @JelleZijlstra
      Member

      This patch adds the C implementation (copied from the PEP).

      Some notes:

      • I added a new .h file in Include/ because there didn't seem to be an obvious existing place to put it.
      • There was some uncertainty about whether we should Py_INCREF the string or bytes returned when a string/bytes is passed in. Running test -l and -L works with the Py_INCREF in and we're adding a new reference to the module, so I think this is correct.
    5. buchuki commented on Jun 3, 2016

      buchukimannequin
      Mannequin

      This patch adds fspath protocol and constructor initialization to pathlib.Path.

    6. ethanfurman commented on Jun 3, 2016

      @ethanfurman
      MemberAuthor

      Note: My schedule changed -- I won't be at the sprints today, but tomorrow. I'll finish reviewing these patches and commit this afternoon if no one beats me to it.

    7. buchuki commented on Jun 3, 2016

      buchukimannequin
      Mannequin

      Adding a glossary entry for path-like. The references are all correct except:

      :class:`os.PathLike` doesn't link to anything because PathLike hasn't been added to the os module yet. Similarly, :meth:`__fspath__` does not link to anything, although I think this is acceptable.

    8. ethanfurman commented on Jun 4, 2016

      @ethanfurman
      MemberAuthor

      Dusty: The pathlib tests looks like it's only testing the PurePath implementation; while this /should/ be sufficient, please add tests for the other classes as well.

    9. python-dev commented on Jun 4, 2016

      python-devmannequin
      Mannequin

      New changeset 780cbe18082e by Ethan Furman in branch 'default':
      bpo-27186: add C version of os.fspath(); patch by Jelle Zijlstra
      https://hg.python.org/cpython/rev/780cbe18082e

    10. ethanfurman commented on Jun 4, 2016

      @ethanfurman
      MemberAuthor

      New changeset 00991aa5fdb5 by Ethan Furman in branch 'default':
      bpo-27182: update fsencode and fsdecode for os.path(); patch by Dusty Phillips
      https://hg.python.org/cpython/rev/00991aa5fdb5

      (had wrong issue # in commit)

    11. ethanfurman commented on Jun 4, 2016

      @ethanfurman
      MemberAuthor

      Jelle: the DirEntry patch looks good so far, but it needs a test for a bytes path.

    12. JelleZijlstra commented on Jun 4, 2016

      @JelleZijlstra
      Member

      Thanks for reviewing. This patch adds tests with a bytes DirEntry.

    13. python-dev commented on Jun 4, 2016

      python-devmannequin
      Mannequin

      New changeset e672cf63d08a by Ethan Furman in branch 'default':
      bpo-27186: add PathLike ABC
      https://hg.python.org/cpython/rev/e672cf63d08a

    14. python-dev commented on Jun 4, 2016

      python-devmannequin
      Mannequin

      New changeset 76b2ddaee6bd by Ethan Furman in branch 'default':
      bpo-27186: fix fsencode/fsdecode and update tests; patch by Jelle Zijlstra
      https://hg.python.org/cpython/rev/76b2ddaee6bd

    15. 21 remaining items

    16. vadmium commented on Jun 13, 2016

      @vadmium
      Member

      I went with os.name == "nt", which is what other scandir() tests use. I’m not sure there is a practical different. Anyway the buildbots seem happier now.

    17. brettcannon commented on Jun 13, 2016

      @brettcannon
      Member

      Thanks for catching my screw-up, Martin; I misread the checks in the file by noticing the "nt" bit but not picking up it was comparing against sys.name instead of sys.platform.

    18. ethanfurman commented on Jun 15, 2016

      @ethanfurman
      MemberAuthor

      os.fspath() will be changed to ensure the output of calling obj.__fspath__() is a str or bytes object.

      So the final behavior of calling os.fspath() will be to return a str or bytes or to raise an exception.

      I'll update the code for this change, as well is the places in the stdlib that do/should be using os.fspath().

    19. python-dev commented on Jun 24, 2016

      python-devmannequin
      Mannequin

      New changeset ea7b6a7827a4 by Brett Cannon in branch 'default':
      Issue bpo-27186: Update os.fspath()/PyOS_FSPath() to check the return
      https://hg.python.org/cpython/rev/ea7b6a7827a4

    20. brettcannon commented on Jun 24, 2016

      @brettcannon
      Member

      And now that I have updated os.fspath() I realize that Ethan said he was going to implement the update. :( If you started on the work, Ethan, I'm really sorry for duplicating your (potential) work.

      I'm going to commit Dusty's glossary term next and then go through and update the docs to use it. At that point that will leave updating os.path as the last explicit step in PEP-519 that needs to be short of updating "What's New". We're getting there. :)

    21. python-dev commented on Jun 24, 2016

      python-devmannequin
      Mannequin

      New changeset 9c57178f13dc by Brett Cannon in branch 'default':
      Issue bpo-27186: Define what a "path-like object" is.
      https://hg.python.org/cpython/rev/9c57178f13dc

    22. brettcannon commented on Jun 24, 2016

      @brettcannon
      Member

      I think with the glossary change, this issue is done! Thanks everyone for the help with getting this far!

      Now on to os.path...

    23. ethanfurman commented on Jun 24, 2016

      @ethanfurman
      MemberAuthor

      Brett, no worries. My time has been extremely limited.

      I'll get the other locations in the stdlib fixed sometime in the next two months if no one beats me to it.

    24. serhiy-storchaka commented on Jul 4, 2016

      @serhiy-storchaka
      Member
    25. brettcannon commented on Jul 4, 2016

      @brettcannon
      Member

      I'm fine with merging the two files if you want to do it. Build rules will also need updating if they do get merged.

    26. erikjanss commented on Aug 6, 2018

      erikjanssmannequin
      Mannequin

      is there a particular reason for PyOS_FSPath to live in posixmodule.c

      since Objects/unicodeobject.c uses this function, this makes it not possible to compile Python without a posixmodule.

      this makes it difficult to compile a 'core' python on a new platform, since implementing the posixmodule on a new platform is not trivial.

      also the documentation on porting mentions that one should first port python without a posixmodule.

    27. brettcannon commented on Aug 6, 2018

      @brettcannon
      Member

      On Mon, Aug 6, 2018, 13:56 Erik Janssens, <[email protected]> wrote:

      Erik Janssens <[email protected]> added the comment:

      is there a particular reason for PyOS_FSPath to live in posixmodule.c

      It's there because the C API for the os module is kept in that module.

    28. erikjanss commented on Aug 13, 2018

      erikjanssmannequin
      Mannequin

      thank you for the info ... I'll have a look at making the posix module easier to port ...

    29. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions