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
Better _binary module use #4614
Conversation
linear = 0 | ||
else: | ||
greyscale = 0 | ||
if self.mode in ["L", "LA", "P", "PA"]: | ||
if greyscale: | ||
if not linear: | ||
self.lut = [i8(c) for c in palette[:256]] | ||
self.lut = list(palette[:256]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In [1]: [c for c in b'test']
Out[1]: [116, 101, 115, 116]
In [2]: list(b'test')
Out[2]: [116, 101, 115, 116]
I don't have enough permissions to restart build on Travis ( |
Maybe you do: try logging out and back in to Travis, that brought back the restart buttons for me recently. |
Thanks, it works) |
@@ -70,7 +69,7 @@ def read_32(fobj, start_length, size): | |||
byte = fobj.read(1) | |||
if not byte: | |||
break | |||
byte = i8(byte) | |||
byte = byte[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it just me, or is byte = byte[0]
not as clear as byte = i8(byte)
about what is happening here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right that i8()
looks more clear at first glance. Mostly because indexing had changed from Py2 to Py3 for bytes. However, this saves one function call and type checking on each value. Also, IDEs handle types correctly and show variables as int.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an alternative, it is possible to change i8 and use it everywhere for consistency:
def i8(c, o=0):
return c[o]
I've created a rebased version of this as #5156 |
s[4:]
).