Support path-like objects in shutil.which()
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず shutil.which() と、bytes およびパスのようなコマンドを対象とするテストを読む。提示された BytesPath の例で TypeError を再現し、コマンドと検索パスの型が一致しているか確認する。bytes を基盤とするパスのようなコマンドが、同等の直接的な bytes コマンドと同じように動作すれば完了。関連する shutil テストを実行する。
索引モデルが issue の本文から書いたものです。
説明
shutil.which() accepts a bytes command and returns a bytes path. It also accepts path-like command objects, but a path-like object whose __fspath__() method returns bytes raises TypeError instead of behaving like the equivalent direct bytes value.
import shutil
class BytesPath:
def __fspath__(self):
return b"python3"
print(shutil.which(b"python3"))
print(shutil.which(BytesPath()))
On CPython main, the first call returns a bytes path and the second fails:
b'/usr/bin/python3'
TypeError: Can't mix strings and bytes in path components
which() checks whether cmd is bytes before resolving the path-like object. It then decodes PATH to str, while os.path.split() has resolved the command to bytes. Calling os.fspath(cmd) before choosing the string or bytes path keeps the command and search path on the same type.
CPython versions tested on
- CPython main branch (
3.16.0a2+)
Operating systems tested on
- Linux ARM64
Linked PRs
- gh-161789
- 主要言語
- Python
- スター
- 78.2k
- フォーク
- 36.6k
- 平均マージ
- 19時間 57分
- マージ済み PR(30日)
- 630
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
stdlib type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
extension-modules stdlib topic-XML type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
python/cpython#161807 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
extension-modules topic-IO type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
platform: import _wmi on first use再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンOS-windows performance stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
python/cpython#161513 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
Email validation accepts a trailing newline対応中かも @marcello-pichini が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
dbt-labs/spark-utils#51 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
bug frontend
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
vendrabuck/HERD#1419 ·
メンテナーはふだん 1 日以内に返信