Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Feature or enhancement
Proposal:
These type checks were introduced a long time ago in5bfc03f and became redundant in3f9183b with the addition ofos.fspath(). They can be safely removed, slightly speeding upos.path.join() in the process:
def join(path, *paths): path = os.fspath(path) if isinstance(path, bytes): sep = b'\\' seps = b'\\/' colon_seps = b':\\/' else: sep = '\\' seps = '\\/' colon_seps = ':\\/' try:- if not paths:- path[:0] + sep #23780: Ensure compatible data type even if p is null.
def join(a, *p): """Join two or more pathname components, inserting '/' as needed. If any component is an absolute path, all previous path components will be discarded. An empty last part will result in a path that ends with a separator.""" a = os.fspath(a) sep = _get_sep(a) path = a try:- if not p:- path[:0] + sep #23780: Ensure compatible data type even if p is null.
I also noticed we're concatenatingb to an empty string inposixpath.join() in casepath has a length of 0. Which we can fix quite easily:
-if b.startswith(sep):+if b.startswith(sep) or not path: path = b-elif not path or path.endswith(sep):+elif path.endswith(sep): path += b
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere