-
Notifications
You must be signed in to change notification settings - Fork 901
Closed
Description
yapf/yapf/yapflib/file_resources.py
Lines 89 to 90 in f6bb994
| if os.path.exists(config_file): | |
| with open(config_file) as fd: |
The above snippet of code can cause problem in case of race condition, where file might be present at the time of if os.path.exists(path) but might not exist when we try to read the file and result in exception. The python EAFP(Easy to Ask for Forgiveness than Permission) philosophy suggests that we use a try catch block to avoid this problem. Suggested changes.
You can read this stackoverflow answer to understand the problem more
Can this issue be assigned to me?
The above snippets can be replaced by the following.
try:
f = open(config_file)
except IOError as e:
print("File can't be accessed")
else:
with f:
config = py3compat.ConfigParser()
config.read_file(fd)
if config.has_section('yapf'):
return config_file```
@gwelymernans
@sergiogiro Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels