Skip to main content

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

Project description

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')
>>> hasattr(bar, 'my_attr')
>>> 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 with pip:

$ pip install flake8-plone-hasattr


  • Python 2.7, 3.3, 3.4
  • flake8


GPL 2.0


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]

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for flake8-plone-hasattr, version 0.2.post0
Filename, size File type Python version Upload date Hashes
Filename, size flake8_plone_hasattr-0.2.post0-py2.py3-none-any.whl (5.1 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size flake8-plone-hasattr-0.2.post0.tar.gz (11.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page