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 — shutil.which() should support bytes · Issue #62483 · python/cpython

shutil.which() should support bytes #62483

New issue
Copy link
New issue
Copy link
Closed
Closed
shutil.which() should support bytes#62483
Copy link
Labels
3.8 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

Arfrever
mannequin
opened on Jun 22, 2013
Issue body actions
BPO 18283
Nosy @loewis, @vstinner, @tarekziade, @hynek, @serhiy-storchaka, @csabella
PRs
  • bpo-18283: Add support for bytes to shutil.which #11818
  • Files
  • which_bytes.patch
  • 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 2019-02-13.11:25:48.982>
    created_at = <Date 2013-06-22.15:29:11.010>
    labels = ['3.8', 'type-feature', 'library']
    title = 'shutil.which() should support bytes'
    updated_at = <Date 2019-02-13.11:25:48.982>
    user = 'https://bugs.python.org/Arfrever'

    bugs.python.org fields:

    activity = <Date 2019-02-13.11:25:48.982>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-02-13.11:25:48.982>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2013-06-22.15:29:11.010>
    creator = 'Arfrever'
    dependencies = []
    files = ['30674']
    hgrepos = []
    issue_num = 18283
    keywords = ['patch']
    message_count = 11.0
    messages = ['191644', '191684', '191686', '191691', '206370', '206373', '206374', '206386', '335141', '335209', '335415']
    nosy_count = 8.0
    nosy_names = ['loewis', 'vstinner', 'tarek', 'Arfrever', 'python-dev', 'hynek', 'serhiy.storchaka', 'cheryl.sabella']
    pr_nums = ['11818']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue18283'
    versions = ['Python 3.8']

    Activity

    1. Arfrever commented on Jun 22, 2013

      @Arfrever
      Arfrevermannequin
      on Jun 22, 2013
      MannequinAuthor
      More actions

      shutil.which() should support bytes. Some other functions in shutil module support bytes.

      >>> shutil.which("echo")
      '/bin/echo'                                                                                                                                                  
      >>> shutil.which(b"echo")                                                                                                                                    
      Traceback (most recent call last):                                                                                                                           
        File "<stdin>", line 1, in <module>                                                                                                                        
        File "/usr/lib64/python3.3/shutil.py", line 1126, in which
          name = os.path.join(dir, thefile)
        File "/usr/lib64/python3.3/posixpath.py", line 92, in join
          "components.") from None
      TypeError: Can't mix strings and bytes in path components.
      >>> shutil.which("echo", path="/bin")
      '/bin/echo'
      >>> shutil.which("echo", path=b"/bin")
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/usr/lib64/python3.3/shutil.py", line 1098, in which
          path = path.split(os.pathsep)
      TypeError: Type str doesn't support the buffer API
      >>> shutil.which(b"echo", path=b"/bin")
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/usr/lib64/python3.3/shutil.py", line 1098, in which
          path = path.split(os.pathsep)
      TypeError: Type str doesn't support the buffer API
    2. Arfrever
      added
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      on Jun 22, 2013
    3. serhiy-storchaka
      added
      type-featureA feature request or enhancementA feature request or enhancement
      on Jun 22, 2013
    4. vstinner commented on Jun 23, 2013

      @vstinner
      vstinner
      on Jun 23, 2013
      Member
      More actions

      Here is an implementation.

    5. serhiy-storchaka commented on Jun 23, 2013

      @serhiy-storchaka
      serhiy-storchaka
      on Jun 23, 2013
      Member
      More actions

      What about bytearrays and other byte-like objects?

      However I'm not sure this enhancement is worth to be accepted. Many other high-level functions in os and shutil modules do not support bytes paths. For shutil.which() there is no backward compatibility with Python 2 which we should support.

    6. vstinner commented on Jun 23, 2013

      @vstinner
      vstinner
      on Jun 23, 2013
      Member
      More actions

      "What about bytearrays and other byte-like objects?

      However I'm not sure this enhancement is worth to be accepted. Many other high-level functions in os and shutil modules do not support bytes paths. For shutil.which() there is no backward compatibility with Python 2 which we should support."

      Bytes is the native type for path on all platforms... except Windows. So I fixed many functions of the os module to support bytes parameters. For example, functions of os.path support str and bytes types, but not bytearray. I also prefer to reject byte-like objects, to keep it simple.

      The bytes type should be accepted for any kind of os function parameter: path, environment variable, command line argument, etc. It's not a question of being compatible with Python 2, an application can make the choice of only used bytes because bytes is the native type for OS data on UNIX.

      Python 3 supports also "bytes stored in Unicode" thanks to the PEP-393, but it's not exactly the same: a path stored as str depends on the filesystem locale, whereas a bytes string is well defined (it's just an array of 8-bit unsigned numbers) and doesn't depend on any configuration variable.

    7. serhiy-storchaka commented on Dec 16, 2013

      @serhiy-storchaka
      serhiy-storchaka
      on Dec 16, 2013
      Member
      More actions

      All low-level functions in the os.path module supports string and bytes paths. But not all high-level functions in the shutil module supports bytes paths. Adding support for bytes paths will complicate implementation and tests.

    8. vstinner commented on Dec 16, 2013

      @vstinner
      vstinner
      on Dec 16, 2013
      Member
      More actions

      Almost all functions of the shutil module support bytes filenames. I tested shutil.copyfile(), shutil.ignore_patterns(), shutil.copytree(), shutil.rmtree() and shutil.move().

      I only found one function which only support Unicode filenames: shutil.make_archive().

    9. python-dev commented on Dec 16, 2013

      @python-dev
      python-devmannequin
      on Dec 16, 2013
      Mannequin
      More actions

      New changeset a1a05e2724dd by Victor Stinner in branch 'default':
      Issue bpo-18283: shutil.which() now supports bytes argument, not only text argument.
      http://hg.python.org/cpython/rev/a1a05e2724dd

    10. vstinner
      closed this as completedon Dec 16, 2013
    11. vstinner commented on Dec 16, 2013

      @vstinner
      vstinner
      on Dec 16, 2013
      Member
      More actions

      which_bytes.patch does not work on Windows.

      According to Serhiy, it's a new feature and so should wait for Python 3.5.

    12. vstinner
      reopened this on Dec 16, 2013
    13. csabella commented on Feb 9, 2019

      @csabella
      csabella
      on Feb 9, 2019
      Contributor
      More actions

      Would it be worthwhile to make a PR of this for 3.8?

    14. csabella
      added
      3.8 (EOL)end of lifeend of life
      on Feb 9, 2019
    15. vstinner commented on Feb 11, 2019

      @vstinner
      vstinner
      on Feb 11, 2019
      Member
      More actions

      Would it be worthwhile to make a PR of this for 3.8?

      Yes. Would you be interested to convert my old patch to a fresh PR? I can help you to work on that.

    16. vstinner commented on Feb 13, 2019

      @vstinner
      vstinner
      on Feb 13, 2019
      Member
      More actions

      New changeset 5680f65 by Victor Stinner (Cheryl Sabella) in branch 'master':
      bpo-18283: Add support for bytes to shutil.which (GH-11818)
      5680f65

    17. vstinner
      closed this as completedon Feb 13, 2019
    18. ezio-melotti
      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

    No one assigned

      Labels

      3.8 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

      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.