Skip to content
This repository was archived by the owner on Apr 20, 2025. It is now read-only.

Create PY2 constant to simplify compatibility decisions #82

Merged
merged 1 commit into from
Jan 15, 2017
Merged

Create PY2 constant to simplify compatibility decisions #82

merged 1 commit into from
Jan 15, 2017

Conversation

adamantike
Copy link
Contributor

Based on discussion at #72, remove try/except-based decisions and use the Python version to clean compatibility decisions

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 91.361% when pulling 4fe1653 on adamantike:compat-py3 into 9f57740 on sybrenstuvel:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 91.677% when pulling 70117bf on adamantike:compat-py3 into 9f57740 on sybrenstuvel:master.

@@ -26,6 +26,8 @@
MAX_INT32 = (1 << 31) - 1
MAX_INT16 = (1 << 15) - 1

PY3 = sys.version_info[0] >= 3
Copy link
Owner

Choose a reason for hiding this comment

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

Let's make this == 3, as PY3 being True on Python 4.x would be rather silly.

Copy link
Contributor Author

@adamantike adamantike Sep 13, 2016

Choose a reason for hiding this comment

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

Yes, that would be more accurate. But as I see it, if Python 4 is released tomorrow, I would prefer to have py3's configurations rather than py2's (unless until a new PY4 constant is added).

With that in mind, what do you think about using a PY2 constant instead?

Copy link
Owner

Choose a reason for hiding this comment

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

👍 on the PY2 constant

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 91.776% when pulling 7b28043 on adamantike:compat-py3 into 9f57740 on sybrenstuvel:master.

return out.getvalue()
else:
def make_buffer():
def make_buffer():
Copy link
Owner

Choose a reason for hiding this comment

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

Hmmmm now that I see how it turns out, I have some doubts about doing the if PY3 inside the function. The way it is now, if PY3 is evaluated for each and every function call. By doing something like this:

if PY3:
    def write_to_stdout(data): ...
    def make_buffer(): ...
else:
    def write_to_stdout(data): ...
    def make_buffer(): ...

we only need to evaluate if PY3 once. This is slightly harder to read, as the PY3 and PY2 versions of the functions are potentially further apart, it does make the runtime execution a bit faster. What do you think @adamantike ?

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 try to prioritize readability and DRYness instead of (over)optimization. Even if these functions don't share logic, I prefer to have a unique point of "failure", one docstring to maintain and shared common blocks inside the function if that's possible.

In my opinion, those advantages will make devs to save a lot more time when trying to contribute to the project or follow a stack trace than one more comparison per call will ever provide. Does that make any sense?

Copy link
Owner

Choose a reason for hiding this comment

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

It makes sense, and I agree that readability is very important. However, I'm also curious as to the runtime performance impact. Do you have time to do some timing tests with some large key generation and file encryption?

@adamantike adamantike changed the title Create PY3 constant to simplify compatibility decisions Create PY2 constant to simplify compatibility decisions Sep 18, 2016
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 91.776% when pulling 45622ad on adamantike:compat-py3 into 9f57740 on sybrenstuvel:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 91.776% when pulling afa9ae1 on adamantike:compat-py3 into 9f57740 on sybrenstuvel:master.

@adamantike
Copy link
Contributor Author

@sybrenstuvel is there something else we should address for this PR? Also, should we consider using six instead?

@sybrenstuvel sybrenstuvel merged commit 81f0e95 into sybrenstuvel:master Jan 15, 2017
@adamantike adamantike deleted the compat-py3 branch January 15, 2017 22:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants