wemake-services / wemake-services/wemake-python-styleguide
New metric: dynamic complexity
@sobolevn is already working on this.
Since Oct 7, 2019.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 430
- Avg merge
- 5h 14m
- Merged PRs (30d)
- 34
Description
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- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.