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

Fixes #906 (BAN-B101) Assert statement used outside of tests #907

Conversation

rohankhanna
Copy link
Contributor

No description provided.

@@ -136,10 +136,12 @@ def loadAggregationSchemas():
try:
if xFilesFactor is not None:
xFilesFactor = float(xFilesFactor)
assert 0 <= xFilesFactor <= 1
if not (0 <= xFilesFactor <= 1):
Copy link
Member

Choose a reason for hiding this comment

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

if aggregationMethod is not None:
if state.database is not None:
assert aggregationMethod in state.database.aggregationMethods
if not (aggregationMethod in state.database.aggregationMethods):
Copy link
Member

Choose a reason for hiding this comment

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

@deniszh
Copy link
Member

deniszh commented Oct 16, 2020

Hi @rohankhanna

Could you please fix PYL-C0325 introduced in your change?

Thanks!

@rohankhanna
Copy link
Contributor Author

@deniszh Is there anything else I should do? Is this good to merge?

@@ -89,7 +89,8 @@ def remove_node(self, key):
self.ring_len = len(self.ring)

def get_node(self, key):
assert self.ring
if not self.ring:
raise AssertionError("self.ring not set")
Copy link
Member

Choose a reason for hiding this comment

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

I'd move this check to the end of the constructor. No point checking this on every get_node(). The whole idea of assertions is that they are optimised away in production code but you can use it while developing/debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't realize that we were deliberately trying to optimise away assertions.

Copy link
Member

@piotr1212 piotr1212 Oct 23, 2020

Choose a reason for hiding this comment

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

This code is 10 years old, no clue what the intention was. I also have no clue why Deepsource thinks having assertions in code outside of tests is a bad thing. I personally don't use them but there are many reasons one might want to, there is many CS research on that topic.

Anyway this looks good to me.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, but now tests fail... Aaargh

Copy link
Member

Choose a reason for hiding this comment

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

We can probably just remove the whole check, it is kinda pointless, if ring = None then the bisect_left() fails anyway.

@deniszh deniszh merged commit 607f6f7 into graphite-project:master Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants