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 should accept pathlib types · Issue #67430 · python/cpython

shutil should accept pathlib types #67430

New issue
Copy link
New issue
Copy link
Closed
Closed
shutil should accept pathlib types#67430
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

mkesper
mannequin
opened on Jan 14, 2015
Issue body actions
BPO 23241
Nosy @vstinner, @bitdancer, @serhiy-storchaka

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 2017-03-27.10:57:17.056>
created_at = <Date 2015-01-14.13:02:56.723>
labels = ['type-bug']
title = 'shutil should accept pathlib types'
updated_at = <Date 2017-03-27.10:57:17.054>
user = 'https://bugs.python.org/mkesper'

bugs.python.org fields:

activity = <Date 2017-03-27.10:57:17.054>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2017-03-27.10:57:17.056>
closer = 'vstinner'
components = []
creation = <Date 2015-01-14.13:02:56.723>
creator = 'mkesper'
dependencies = []
files = []
hgrepos = []
issue_num = 23241
keywords = []
message_count = 4.0
messages = ['234025', '234027', '290508', '290582']
nosy_count = 4.0
nosy_names = ['vstinner', 'r.david.murray', 'mkesper', 'serhiy.storchaka']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue23241'
versions = ['Python 3.4']

Activity

  1. mkesper commented on Jan 14, 2015

    @mkesper
    mkespermannequin
    on Jan 14, 2015
    MannequinAuthor
    More actions
    source_path = Path('../data')
    destination_path = Path('//file_server/work/whatever')
    for file_name in source_path.glob('xyz-*'):
        shutil.copyfile(source_path / file_name, destination_path / file_name)

    leads to:

    Traceback (most recent call last):
      File "copy_shares_2_work.py", line 9, in <module>
        shutil.copyfile(source_path / file_name, destination_path / file_name)
      File "C:\Python34\lib\shutil.py", line 90, in copyfile
        if _samefile(src, dst):
      File "C:\Python34\lib\shutil.py", line 75, in _samefile
        return os.path.samefile(src, dst)
      File "C:\Python34\lib\genericpath.py", line 90, in samefile
        s1 = os.stat(f1)
    TypeError: argument should be string, bytes or integer, not WindowsPath

    Converting to str() works but is unexpected.

  2. mkesper
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jan 14, 2015
  3. bitdancer commented on Jan 14, 2015

    @bitdancer
    bitdancer
    on Jan 14, 2015
    Member
    More actions

    This is a specific example of a global discussion about handling of paths in the stdlib. So far we have elected not to provide special handling. The correct thing to do is call str. I'm not sure if shutil is special enough to be a special case, but it would need to be discussed in the context of the larger issue in some forum other than the bug tracker (probably python-dev).

  4. serhiy-storchaka commented on Mar 26, 2017

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

    Is this issue outdated since implementing a file system path protocol (PEP-519) in 3.6?

  5. vstinner commented on Mar 27, 2017

    @vstinner
    vstinner
    on Mar 27, 2017
    Member
    More actions

    I'm unable to reproduce the bug on Python 3.6:
    ---

    from pathlib import Path
    import shutil
    import os
    def touch(name):
        with open(name, "x"):
            pass
    os.mkdir('a')
    touch('a/x')
    touch('a/y')
    touch('a/z')
    os.mkdir('b')
    source_path = Path('a')
    destination_path = Path('b')
    for file_name in source_path.glob('*'):
        file_name = file_name.name
        src = source_path / file_name
        dst = destination_path / file_name
        print("%r -> %r" % (src, dst))
        shutil.copyfile(src, dst)

    Output:
    ---
    PosixPath('a/y') -> PosixPath('b/y')
    PosixPath('a/x') -> PosixPath('b/x')
    PosixPath('a/z') -> PosixPath('b/z')
    ---

    Thank you PEP-519 ;-)

  6. vstinner
    closed this as completedon Mar 27, 2017
  7. 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

    type-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.