Skip to content
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

Redo variable and function names reserved for Python #165

Closed
wants to merge 1 commit into from

Conversation

vagishagupta23
Copy link
Contributor

@vagishagupta23 vagishagupta23 commented Jun 10, 2019

Changed the conflicting variable name filter and function name
filter() which suricata-update uses as it is reserved for use in
Python standard modules.

Make sure these boxes are signed before submitting your Pull Request
-- thank you.

Link to redmine ticket: https://redmine.openinfosecfoundation.org/issues/3012

Describe changes:

  • Changed variable and function names filter in main.py
  • Changed variable and function names filter in test_main.py

Changed the conflicting variable name `filter` and function name
`filter()` accordingly which suricata-update uses as it is reserved
for use in Python standard modules.
@@ -252,7 +252,7 @@ def __init__(self, matcher, pattern, repl):
def match(self, rule):
return self.matcher.match(rule)

def filter(self, rule):
def modify_filter(self, rule):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeating the functionality of a class in its methods is usually a bad practice. What I mean is, when you want to access this function, you'd probably do ModifyRuleFilter.modify_filter() see the modify twice? Was it even needed? Probably not. Because in this case filter has been defined under a separate namespace. Hence, ModifyRuleFilter.filter() makes a better candidate. However, since filter() is reserved, we should in any circumstances avoid using it directly. The next best thing would be _filter(). But, it is used to indicate private use methods.
Conclusion: I think something should be changed here, I can't think of a good function name. Please find something?
Also, if you think otherwise or find some guide/docs that provide a clear picture of naming scheme in such cases, please let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @shivan1b I tried going through many guide/docs for such cases but couldn't find one. I could come up with a few names for the filter() function like filterRule(), drop()/modify(), dropRule()/modifyRule()and filtered(). Do you think any of these could be used?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I guess then we should leave this as-is. Let @jasonish decide if this looks OK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So part of the idea is that a filter follows an interface, so executing doesn't require knowledge of what its doing. I'd prefer to rename the method to something more generic.. run(), or execute() seem to be common names in other languages where filters are part of a processing pipeline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying @jasonish. Will fix it in a new PR.

@@ -291,7 +291,7 @@ def match(self, rule):
return False
return self.matcher.match(rule)

def filter(self, rule):
def drop_filter(self, rule):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@vagishagupta23
Copy link
Contributor Author

Created a new PR #174.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants