flake8-blind-except-0.2.0/0000775000175000017500000000000013775660537015206 5ustar jriverojriveroflake8-blind-except-0.2.0/setup.py0000664000175000017500000000176513775660537016731 0ustar jriverojriverofrom setuptools import setup def get_version(fname='flake8_blind_except.py'): with open(fname) as f: for line in f: if line.startswith('__version__'): return eval(line.split('=')[-1]) def get_long_description(): descr = [] for fname in ('README.rst',): with open(fname) as f: descr.append(f.read()) return '\n\n'.join(descr) setup( name='flake8-blind-except', description='A flake8 extension that checks for blind except: statements', long_description=get_long_description(), keywords='flake8 except exception', version=get_version(), author='Elijah Andrews', author_email='elijahcandrews@gmail.com', install_requires=['setuptools'], entry_points={ 'flake8.extension': [ 'B90 = flake8_blind_except:check_blind_except' ], }, url='https://github.com/elijahandrews/flake8-blind-except', license='MIT', py_modules=['flake8_blind_except'], zip_safe=False, ) flake8-blind-except-0.2.0/README.rst0000664000175000017500000000505113775660537016676 0ustar jriverojriveroflake8-blind-except =================== A flake8 extension that checks for blind, catch-all ``except:`` and ``except Exception:`` statements. As of `pycodestyle 2.1.0 `_, "E722 do not use bare except, specify exception instead" is built-in. However, bare ``Exception`` and ``BaseException`` are still allowed. This extension flags them as `B902`. Using ``except`` without explicitly specifying which exceptions to catch is generally considered bad practice, since it catches system signals like ``SIGINT``. You probably want to handle system interrupts differently than exceptions occuring in your code. It's also usually better style to have many small ``try``-``except`` blocks catching specific exceptions instead of a giant ``try:`` block with a catch-all ``except:`` at the bottom. It's also nicer to your fellow programmers to be a bit more specific about what exceptions they can expect in specific parts of the code, and what the proper course of action is when they occur. An example of code that will fail this check is: .. code-block:: python try: something_scary() except: everybody_panic() However, the following code is valid: .. code-block:: python try: something_terrifying() except TerrifyingException: dont_panic() Installation ------------ If you don't already have it, install ``flake8``:: $ pip install flake8 Then, install the extension:: $ pip install flake8-blind-except Usage ----- Run the following to verify that the plugin has been installed correctly:: $ flake8 --version 2.0 (pep8: 1.4.6, flake8-blind-except: 0.1.0, pyflakes: 0.7.3) Now, when you run ``flake8``, the plugin will automatically be used. When a blind except is found, ``flake8`` will output:: B901 blind except: statement or:: B902 blind except Exception: statement Contributing ------------ I'm not working on Python these days, so probably won't be making updates anytime soon. PRs are welcome though! Testing ------- Tests can be run with ``pytest --doctest-modules flake8_blind_except.py``. Changes ------- 0.2.0 - 2021-01-07 `````````````````` * B902 error added for cases where a blind ``Exception`` is caught. 0.1.1 - 2016-06-27 `````````````````` * ``pep8`` was renamed to ``pycodestyle`` in its 2.0 release. Compatibility update for this change. 0.1.0 - 2014-02-07 `````````````````` * Initial release Notes ----- I've tested this package with flake8 2.6.2 + Python 2.7.3 and flake8 3.7.9 + Python 3.7.5. flake8-blind-except-0.2.0/.gitignore0000664000175000017500000000047313775660537017202 0ustar jriverojrivero*.py[cod] # C extensions *.so # Packages *.egg *.egg-info dist build eggs parts bin var sdist develop-eggs .installed.cfg lib lib64 __pycache__ # Installer logs pip-log.txt # Unit test / coverage reports .coverage .tox nosetests.xml # Translations *.mo # Mr Developer .mr.developer.cfg .project .pydevproject flake8-blind-except-0.2.0/flake8_blind_except.py0000664000175000017500000000307713775660537021461 0ustar jriverojriverotry: import pycodestyle except ImportError: import pep8 as pycodestyle import re __version__ = '0.2.0' BLIND_EXCEPT_REGEX = re.compile(r'(^[ \t]*except(.*\b(Base)?Exception\b.*)?:)') # noqa def check_blind_except(physical_line): """Check for blind except statements. >>> check_blind_except('except:') (0, 'B901 blind except: statement') >>> check_blind_except('except Exception:') (0, 'B902 blind except Exception: statement') >>> check_blind_except('except Exception as exc:') (0, 'B902 blind except Exception: statement') >>> check_blind_except('except ValueError, Exception as exc:') (0, 'B902 blind except Exception: statement') >>> check_blind_except('except Exception, ValueError as exc:') (0, 'B902 blind except Exception: statement') >>> check_blind_except('except BaseException as exc:') (0, 'B902 blind except Exception: statement') >>> check_blind_except('except GoodException as exc: # except:') >>> check_blind_except('except ExceptionGood as exc:') >>> check_blind_except('except Exception') # only trigger with trailing colon >>> check_blind_except('some code containing except: in string') """ if pycodestyle.noqa(physical_line): return match = BLIND_EXCEPT_REGEX.search(physical_line) if match: if match.group(2) is None: return match.start(), 'B901 blind except: statement' else: return match.start(), 'B902 blind except Exception: statement' check_blind_except.name = 'flake8-blind-except' check_blind_except.version = __version__ flake8-blind-except-0.2.0/LICENSE0000664000175000017500000000207113775660537016213 0ustar jriverojriveroThe MIT License (MIT) Copyright (c) 2014 Elijah Andrews Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.