Skip to content

fix: replace deprecated posixpath.commonprefix() with startswith()#340

Open
frenzymadness wants to merge 2 commits into
pypa:mainfrom
frenzymadness:commonprefix
Open

fix: replace deprecated posixpath.commonprefix() with startswith()#340
frenzymadness wants to merge 2 commits into
pypa:mainfrom
frenzymadness:commonprefix

Conversation

@frenzymadness

Copy link
Copy Markdown

os.path.commonprefix() is deprecated in Python 3.15 and emits a DeprecationWarning. Replace all three usages with str.startswith() checks, which are also semantically more correct (commonprefix does character-level matching and can produce false positives for paths sharing a string prefix but not a directory boundary).

Without this, TestInstall.test_skips_pycache_and_warns fails with Python 3.15 because the code generated more warnings than expected.

frenzymadness and others added 2 commits June 18, 2026 20:58
os.path.commonprefix() is deprecated in Python 3.15 and emits a
DeprecationWarning. Replace all three usages with str.startswith()
checks, which are also semantically more correct (commonprefix does
character-level matching and can produce false positives for paths
sharing a string prefix but not a directory boundary).
@Secrus

Secrus commented Jun 19, 2026

Copy link
Copy Markdown
Member

Python docs mention using commonpath instead of commonprefix yet you used str.startswith. Any particular reason for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants