skip to navigation
skip to content

flake8-plone-hasattr 0.2.post0

Checks for hasattr, which is considered harmful in Plone projects.

Flake8 Plone hasattr plugin

Python standard hasattr is considered harmful (within Plone projects).

The (hidden) problem with hasattr is that it swallows exceptions, which in your normal business logic you really don’t want to.

Specially in Plone context that could mean swallowing a database error, or a permission exception, etc.

Take, for instance, the following code:

>>> class Foo(object):
...     @property
...     def my_attr(self):
...         raise ValueError('nope, nope, nope')
...
>>> bar = Foo()
>>> bar.my_attr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in my_attr
ValueError: nope, nope, nope
>>> hasattr(Foo, 'my_attr')
True
>>> hasattr(bar, 'my_attr')
False
>>> getattr(bar, 'my_attr', None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in my_attr
ValueError: nope, nope, nope

This plugin is based on a python checker that was in plone.recipe.codeanalysis.

Install

Install with pip:

$ pip install flake8-plone-hasattr

Requirements

  • Python 2.7, 3.3, 3.4
  • flake8

License

GPL 2.0

Changelog

0.2.post0 (2017-05-31)

  • Release universal wheels [gforcada]

0.2 (2017-05-31)

  • Added support for sublimetext (stdin/filename handling) [iham]

0.1 (2015-09-15)

  • Initial release [gforcada]
  • Create the flake8 plugin per se. [gforcada]
 
File Type Py Version Uploaded on Size
flake8-plone-hasattr-0.2.post0.tar.gz (md5) Source 2017-05-31 11KB
flake8_plone_hasattr-0.2.post0-py2.py3-none-any.whl (md5) Python Wheel py2.py3 2017-05-31 4KB