Repository navigation
Conversation
There is no need to decode the file in order to extract the version number from it.
`exec()` can handle the decoding better
to be coherent with the example linked to below
There was a problem hiding this comment.
can we add some explanation of the use of 'rb' and 'br' to convince readers (and me) that this will always work.
There was a problem hiding this comment.
I don't see this change as an advantage. It's technically correct, I guess, but the files in question are actually text files, and reading them as such seems more logical (even if it does mean you need to think about encodings).
Binary reading a text file just to avoid thinking about encodings feels like a hack (and the sort of thinking that the string changes in Python 3 were explicitly designed to discourage).
There was a problem hiding this comment.
What we're trying to extract, i.e. the version number, only uses a subset of ascii characters, so we don't need to deal with unicode. 'rb' tells python to read the file as bytes without trying to decode them, and since we're reading bytes we need the regexp pattern to be bytes (otherwise python 3 will raise TypeError: cannot use a string pattern on a bytes-like object), thus 'br'.
There was a problem hiding this comment.
Would this be satisfactory?
# Since version numbers only use a subset of ascii, we can read the file
# as bytes, thus avoiding unicode decode errors.
There was a problem hiding this comment.
Note: I did search the stdlib for a function that properly decodes a python file (i.e. by looking for the # coding: header), but I couldn't find one, so reading the file as bytes is easier.
There was a problem hiding this comment.
These exist in Python 3 (as tokenize.open() and tokenize.detect_encoding()), but for 2/3 compatible code, assuming ASCII compatibility and reading the bytes is the most straightforward option. We assume ASCII compatibility in other aspects of the packaging ecosystem (most notably distribution package names), so it's a reasonable assumption to make here as well.
|
If there are no other concerns then this is ready for merge. |
|
Ping. |
There was a problem hiding this comment.
storing in locals might be better? exec(fp.read(), {}, about)
There was a problem hiding this comment.
storing in locals might be better?
exec(fp.read(), {}, about)
Why? By separating globals and locals it's no longer obvious that the variables will end up in the right dictionary.
There was a problem hiding this comment.
Because globals gets cluttered with all the various builtins. Locals will just contain what __about__.py defines. It may not matter much for this specific use case, but if we're recommending code we should follow good practice (and using locals is good practice here, IMO).
There was a problem hiding this comment.
Okay, that makes sense, I've made the change.
|
Anything else? |
|
It looks like we all forgot about this PR. Is someone willing to merge it? |
|
Okay, I give up. |
These are all the code improvements that were in #190 before it got scaled back, remade in small commits.