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')
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]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flake8-plone-hasattr-0.2.post0.tar.gz.
File metadata
- Download URL: flake8-plone-hasattr-0.2.post0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f72ef91a47de847f80749a3668aad89fb23f0e6dcf93a1100b0e909b9e378ec6
|
|
| MD5 |
f5fa93cef4630f3eec3af1bbab90d138
|
|
| BLAKE2b-256 |
dbd463e659daf3b6d08854b7a6cd1d90743fe610cf33c4302ab0484d88ce2c49
|
File details
Details for the file flake8_plone_hasattr-0.2.post0-py2.py3-none-any.whl.
File metadata
- Download URL: flake8_plone_hasattr-0.2.post0-py2.py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfabd900e3ac68c47f46e4fa82e5db23463ceb954fc91e2a3b209f3c810e0c3f
|
|
| MD5 |
aa477eeef0a42d676ea4b59b7925b744
|
|
| BLAKE2b-256 |
3c6274fad8a02d5e340b22505c19f3910e60a65f41df3a424a65e1cf3ec9c81e
|