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

python2 & python3 compatibility without needing 'builtins' module for python2 #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

LRGH
Copy link

@LRGH LRGH commented Mar 15, 2017

Because import builtins fails on default installs of python2, and it is not necessary to deal with the fact that bytes is different from python2 to python3.

@bdcht
Copy link
Owner

bdcht commented Mar 17, 2017

I'd rather prefer a solution where we can still choose to rely on builtins: on ImportError you define a 'newbytes(x)' function that unpacks or packs depending on 'x'.

@LRGH
Copy link
Author

LRGH commented Mar 17, 2017

Why do you want to hide the difference between packing and unpacking?
I find it always easier to understand when the type of the variables is explicit.

@bdcht
Copy link
Owner

bdcht commented Mar 17, 2017

the goal is not to hide x type, but to still allow the use of builtins module while minimising modified loc. Rather than defining only a 'newbytes' then define 2 funcs: a 'byteslist' for unpacks and a 'newbytes' for packs so that at import time we can choose which implementation (builtins or struct based) to use.

@LRGH
Copy link
Author

LRGH commented Mar 17, 2017

But the builtins modules provides a big machinery that in the case of crysp is not needed: the use of struct.pack and struct.unpack is sufficient. Why would you want to use builtins?
Nevertheless, I agree that my patch is not optimal, I created a few unnecessary intermediate local variables e.g. in crc.py.

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.

2 participants