Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP8: Avoid bare except: #717

Merged
merged 1 commit into from
Oct 28, 2021
Merged

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Sep 24, 2021

Do not use bare except:, it also catches unexpected events like memory errors, interrupts, system exit, and so on.
Prefer except Exception:. If you’re sure what you’re doing, be explicit and write except BaseException:.

https://realpython.com/the-most-diabolical-python-antipattern/
https://www.python.org/dev/peps/pep-0008/

$ python3 -c "basestring" # --> NameError: name 'basestring' is not defined

$ BUILTINS=assert_equals,assert_exception,inputs,is_resumed,NUM_FOREACH,NUM_LINES,ResumeFromHere,TestRetry
$ flake8 . --builtins=$BUILTINS --count --select=E9,F63,F7,F82 --show-source --statistics

./metaflow/metaflow/parameters.py:13:15: F821 undefined name 'basestring'
    strtype = basestring
              ^
./metaflow/metaflow/util.py:16:20: F821 undefined name 'unicode'
    unicode_type = unicode
                   ^

@savingoyal savingoyal merged commit cc829c4 into Netflix:master Oct 28, 2021
@cclauss cclauss deleted the avoid-bare-except branch October 28, 2021 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants