[Python-Dev] [Python-checkins] cpython: Issue #15031: Refactor some code in importlib pertaining to validating
Brett Cannon
brett at python.org
Sat Jan 12 14:57:39 CET 2013
On Fri, Jan 11, 2013 at 9:55 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> 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: "<bytecode>")
Good suggestion.
>
>> + if path is not None:
>> + exc_details['path'] = path
>> + magic = data[:4]
>> + raw_timestamp = data[4:8]
>> + raw_size = data[8:12]
>> + if magic != _MAGIC_BYTES:
>> + msg = 'bad magic number in {!r}: {!r}'.format(name, magic)
>> + raise ImportError(msg, **exc_details)
>> + elif len(raw_timestamp) != 4:
>> + message = 'bad timestamp in {!r}'.format(name)
>> + _verbose_message(message)
>> + raise EOFError(message)
>> + elif len(raw_size) != 4:
>> + message = 'bad size in {!r}'.format(name)
>> + _verbose_message(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).
True. Those were the original messages and in hindsight not accurate.
Since we don't consider exception messages a backwards-compatible
thing I'll update them.
More information about the Python-Dev
mailing list