quantifiedcode / python-anti-patterns

An open collection of Python anti-patterns and worst practices.
https://quantifiedcode.github.io/python-anti-patterns
Other
1.71k stars 249 forks source link

readability/EAFP: update to Py 3, use specific exception, add race condition note #144

Closed kwi-dk closed 4 years ago

kwi-dk commented 4 years ago

Add a note about the non-EAFP example code also having a potential race condition (which is one of the reasons why the EAFP style is preferred).

Update best practice code to catch the specific FileNotFoundError (new in Python 3.3), instead of the overly broad OSError. (Add note about using OSError in Python 2, but caution that it may be too broad.)

Update glossary link to point to Python 3 docs, for good measure.

dmtucker commented 4 years ago

Related: #125