[Python-Dev] [Python-checkins] cpython: Issue #15031: Refactor some code in importlib pertaining to validating (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Sat Jan 12 03:55:25 CET 2013


Nice improvement. Just a couple of minor cleanup suggestions.

On Sat, Jan 12, 2013 at 9:09 AM, brett.cannon <python-checkins at python.org> wrote:

+ else: + # To prevent having to make all messages have a conditional name. + name = 'bytecode'

For consistency with other default/implied names, I suggest wrapping this in angle brackets: "")

+ if path is not None: + excdetails['path'] = path + magic = data[:4] + rawtimestamp = data[4:8] + rawsize = data[8:12] + if magic != MAGICBYTES: + msg = 'bad magic number in {!r}: {!r}'.format(name, magic) + raise ImportError(msg, **excdetails) + elif len(rawtimestamp) != 4: + message = 'bad timestamp in {!r}'.format(name) + verbosemessage(message) + raise EOFError(message) + elif len(rawsize) != 4: + message = 'bad size in {!r}'.format(name) + verbosemessage(message) + raise EOFError(message)

For timestamp and size "incomplete" would probably be a better word than "bad" in the error messages (since we're only checking the length rather than the value).

Cheers, Nick.

-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia



More information about the Python-Dev mailing list