RUF071 recommends using os.path.commonpath over os.path.commonprefix. However, that is not always desirable, and sometimes even incorrect. The documentation should cover the differences in semantics as well as cases where RUF071 should be ignored.
This rule's recommendation is confusing for those using os.path.commonprefix with non-path strings (which I think is perfectly legitimate):
>> commonprefix(["123", "124"])
'12'
>> commonpath(["123", "124"])
''
I am not sure of the status of a string.commonprefix method in Python 3.15, but I think ruff's wording should be more carefully consider use cases such the one above.
Originally posted by @bersbersbers in #22981
RUF071 recommends using
os.path.commonpathoveros.path.commonprefix. However, that is not always desirable, and sometimes even incorrect. The documentation should cover the differences in semantics as well as cases where RUF071 should be ignored.Originally posted by @bersbersbers in #22981