[SIM906] Merge nested os.path.join calls
See original GitHub issueExplanation
Explain briefly why you think this makes the code simpler.
- This is a common but fun one I have noticed. I have noticed this pattern occur a lot and I believe in most cases it can be simplified to a single function call. I guess this would be kinda of similar to the isinstance checks where people don’t realize the function can consume multiple args.
Example
a = "/a"
b = "b"
c = "c"
# Bad
os.path.join(a,os.path.join(b,c))
# Good
os.path.join(a,b,c)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Is there a way to combine more than 2 file paths at once?
I want to combine multiple file maths together, but I end up with nested stuff like os.path.join(os.path.join(“assets”, “imgs”), ...
Read more >os.path — Common pathname manipulations — Python 3.11 ...
Join one or more path components intelligently. The return value is the concatenation of path and any members of *paths with exactly one...
Read more >Python os.path.join() method [Practical Examples]
This means that we can merge multiple parts of a path into one using the os.path.join method instead of hard-coding every pathname manually....
Read more >Python | os.path.join() method - GeeksforGeeks
path module is sub-module of OS module in Python used for common pathname manipulation. os.path.join() method in Python join one or more path ......
Read more >Why you should be using pathlib - Trey Hunner
from os.path import abspath, dirname, join as joinpath BASE_DIR ... The os.path module requires function nesting, but the pathlib modules' ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@MartinThoma True, but there can be performance issues with using Pathlib. For instance, I think the black formatter removed / reworked a lot of their Pathlib usage back to os.path in their library due to performance issues.