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
One should rather do:
>>> 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
Or in case you want to handle an exception:
>>> try:
... value = getattr(bar, 'my_attr', None)
... exception ValueError:
... value = None
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 3.11+ and pypy3
- flake8
License
GPL 2.0
Metadata
Release files for flake8-plone-hasattr 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flake8_plone_hasattr-1.3.0.tar.gz | 13.5 kB | Without provenance | Details for flake8_plone_hasattr-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flake8_plone_hasattr-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for flake8_plone_hasattr-1.3.0-py3-none-any.whl |
Total release size: 30.2 kB
Release files / flake8_plone_hasattr-1.3.0.tar.gz
| Download URL | flake8_plone_hasattr-1.3.0.tar.gz |
|---|---|
| Size | 13.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
994cd25025be6881e883601e11d1086e36ac711749c3437c19720e348b7cee20
|
|
BLAKE2b-256 checksum How to use checksums |
17b2f2fb3e88ca161cc0f8d5909fcf712ebda8157ae8d49b68f83db3d24e1966
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / flake8_plone_hasattr-1.3.0-py3-none-any.whl
| Download URL | flake8_plone_hasattr-1.3.0-py3-none-any.whl |
|---|---|
| Size | 16.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2f07a0b52eceb41887dafd3ec3bf40a33fed8f8fad187c1c913b465e4dda3640
|
|
BLAKE2b-256 checksum How to use checksums |
f8f343ebdca809b544c531c851b9a15379bee4f525323c4189cdbb1671198c29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Security for flake8-plone-hasattr 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.