python / python/cpython

Difference in _use_fd_functions in shutil.py and test_shutil.py

Open
#119,048 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

When switching from os.listdir to os.scandir 7 years ago somebody forgot to update the definition of _use_fd_functions in test_shutil together with shutil module.

in shutil:

_use_fd_functions = ({os.open, os.stat, os.unlink, os.rmdir} <=
                     os.supports_dir_fd and
                     os.scandir in os.supports_fd and
                     os.stat in os.supports_follow_symlinks)

in test_shutil:

        _use_fd_functions = ({os.open, os.stat, os.unlink, os.rmdir} <=
                             os.supports_dir_fd and
                             os.listdir in os.supports_fd and
                             os.stat in os.supports_follow_symlinks)

I believe there is no need to calculate this variable twice so I'm gonna propose a PR where I use the value from shutil.py in its tests. Nobody will ever forget to update both places again.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the _use_fd_functions definitions in shutil.py and test_shutil.py, then inspect how the test-side value is used. Run the shutil tests to confirm the current behavior and verify that the tests use the module's single value without changing coverage or platform-specific behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.