-
-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New metric: dynamic complexity #393
Comments
Guys, I would love to hear your opinions / suggestions on this topic: @proofit404 @malinoff @orsinium |
decorator |
We also can check |
3 point isn't so moot as other, because all these methods have much better way to use it. You can write |
This:
Or this:
First one is faster and shorter. |
@orsinium considering your example: thanks, I have added it to the list. We should also track some |
I think we can deny def decorator_name(f):
def wrapper(*args, **kwargs): # <- this is fine, decorator can be applied to any function
return f(*args, **kwargs)
return wrapper |
I'm not sure about metaclasses. Is this related to the Django model or Injector from the |
Hold on, guys, I was not clear enough. The purpose of this metric is not to deny, but to count occurrences of the given examples. So, it is pretty much the same as McCabe complexity. We just count uses of these structures and if it tops the threshold then we raise a violation. I have copied this explanation to the issue's body. |
@sobolevn It is not clear to me, what is "dynamic" or "magic" in decorators and properties. For me "dynamic" as opposite to static, must be something that can increase probability of runtime fails or make their error messages less clear. For example, using There is no possibility for such effects in properties. Using property will produce errors in same situations as in plain method. Same with decorators. |
Yes, I agree with @uhbif19 I have spent multiple hours thinking and implementing this feature. It is not ready yet, but I hope to release it one day. |
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 parametersgetattr
,setattr
,hasattr
functions.__setattr__
,.__div__
, etc__name__
,__file__
, etc@property
*
and**
for argument expansionAttributeError
,KeyError
,IndexError
We 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.
The text was updated successfully, but these errors were encountered: