Rule request
Thesis
Original idea belongs to: Tin Markovic.
We need to detect functions that use too much dynamic features of python or so called "magic".
So, it is pretty much the same as McCabe complexity but for dynamic structures.
We just count uses of these structures and if it tops the threshold then we raise a violation.
What do we count as "magic"? Here's the list to be extended:
*args and **kwargs in function parameters
getattr, setattr, hasattr functions
- all direct magic methods:
.__setattr__, .__div__, etc
- all magic constants:
__name__, __file__, etc
@property
* and ** for argument expansion
- decorators, despite being tracked individually
- catching
AttributeError, KeyError, IndexError
We can also try to implement the same metric for classes. This way we can control:
- metaclasses
__slots__ and other magic fields
- magic methods
- decorators, despite being tracked individually
Reasoning
We need to track thing that might fail. We need to be extra careful with magic, since it is hard to use.
Status
This is an early draft. Please, feel free to suggest any ideas about this topic.
Rule request
Thesis
Original idea belongs to: Tin Markovic.
We need to detect functions that use too much dynamic features of python or so called "magic".
So, it is pretty much the same as McCabe complexity but for dynamic structures.
We just count uses of these structures and if it tops the threshold then we raise a violation.
What do we count as "magic"? Here's the list to be extended:
*argsand**kwargsin function parametersgetattr,setattr,hasattrfunctions.__setattr__,.__div__, etc__name__,__file__, etc@property*and**for argument expansionAttributeError,KeyError,IndexErrorWe can also try to implement the same metric for classes. This way we can control:
__slots__and other magic fieldsReasoning
We need to track thing that might fail. We need to be extra careful with magic, since it is hard to use.
Status
This is an early draft. Please, feel free to suggest any ideas about this topic.