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

Python 3 compatibility syntax error fixes #10519

Merged
merged 5 commits into from
Aug 28, 2017
Merged

Python 3 compatibility syntax error fixes #10519

merged 5 commits into from
Aug 28, 2017

Conversation

adityahase
Copy link
Member

erpnext port

while running bench --site site1.local install-app erpnext few syntax errors occur this PR fixes that

"""
(x1, x2) and (y1, y2) are two ranges
if condition x = 100 to 300
then condition y can only be like 50 to 99 or 301 to 400
hence, non-overlapping condition = (x1 <= x2 < y1 <= y2) or (y1 <= y2 < x1 <= x2)
"""
(x1, x2), (y1, y2) = x, y
separate = (x1 <= x2 <= y1 <= y2) or (y1 <= y2 <= x1 <= x2)
return (not separate)
Copy link
Contributor

Choose a reason for hiding this comment

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

remove redundant parenthesis

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess those are necessary there. I can rewrite that as

x1, x2 = x
y1, y2 = y

But not as

(x1, x2), (y1, y2) = x, y

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant in the return statement --> return not separate instead of return(not separate). It's just a code clean up similar to removing the extra spaces

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh. Will create a separate PR soon for these kind of clean ups.

@@ -54,13 +54,14 @@ def sort_shipping_rule_conditions(self):
d.idx = i + 1

def validate_overlapping_shipping_rule_conditions(self):
def overlap_exists_between((x1, x2), (y1, y2)):
def overlap_exists_between(x, y):
"""
(x1, x2) and (y1, y2) are two ranges
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of x and y, use a more descriptive parameter name. Something like num_range1 and num_range2 immediately makes it easy to know what is going on in the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -54,13 +54,14 @@ def sort_shipping_rule_conditions(self):
d.idx = i + 1

def validate_overlapping_shipping_rule_conditions(self):
def overlap_exists_between((x1, x2), (y1, y2)):
def overlap_exists_between(x, y):
"""
(x1, x2) and (y1, y2) are two ranges
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the documentation as well

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.
How can I make it better than it currently is?

@@ -16,5 +16,5 @@ def execute():
try:
reset_perms(doctype)
except:
print "Error resetting perms for", doctype
print("Error resetting perms for", doctype)
raise
Copy link
Contributor

Choose a reason for hiding this comment

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

You left this out. raise in this form is not python 3 compatible. The python 3 compatible form is also not compatible with python 2. However, six is a dependency so use six.reraise

Copy link
Member Author

Choose a reason for hiding this comment

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

Um. I read accepted answer from this Stack Overflow question. I'm confused.

Anyways. That doesn't really prevent me from running bench --site site1.local install-app erpnext as of now. I'll tackle that when it becomes a problem. Cool?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops. You are right. I was wrong. There's nothing wrong with that raise statement

@adityahase adityahase closed this Aug 28, 2017
@adityahase adityahase reopened this Aug 28, 2017
@rmehta rmehta merged commit 6ccb656 into frappe:develop Aug 28, 2017
@adityahase adityahase deleted the install3 branch August 31, 2017 16:58
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