Skip to content

Rule to advise os.path.commonprefix is wrong and you should use os.path.commonpath #22981

@notatallshaw

Description

@notatallshaw

Summary

commonprefix is a string comparison, not a path comparison:

commonprefix(['/usr/lib', '/usr/local/lib'])'/usr/l' (string prefix; not a valid directory)
commonpath(['/usr/lib', '/usr/local/lib'])'/usr' (valid path)

If a user is importing from os.path there is a 99.99% chance they want a path function not a string function.

commonpath was added in Python 3.5 to fix this odd commonprefix behavior: python/cpython#54604

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedReady for implementationruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions