Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bpo-25711: Rewrite zipimport in pure Python.#6809

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
serhiy-storchaka merged 17 commits intopython:masterfromserhiy-storchaka:zipimport
Sep 18, 2018

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedMay 14, 2018
edited by bedevere-bot
Loading

zware, alex, and gst reacted with thumbs up emoji
@serhiy-storchakaserhiy-storchaka requested a review froma team as acode ownerJuly 8, 2018 17:21

path = _get_module_path(self, fullname)
if mi:
fullpath = path + path_sep + '__init__.py'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

bootstrap_external._path_join()

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What is the benefit of usingbootstrap_external._path_join()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Readability. When I readpath + path_sep + '__init__.py' I have to mentally piece together that this is constructing a file path, while_path_join(path, '__init__.py)` gives me that context implicitly.

if mi:
fullpath = path + path_sep + '__init__.py'
else:
fullpath = path + '.py'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Might as well use an f-string.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What is the benefit of using an f-string instead of+ for concatenating two strings?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I find it more readable.

# add __path__ to the module *before* the code gets
# executed
path = _get_module_path(self, fullname)
fullpath = f'{self.archive}{path_sep}{path}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

_bootstrap_external._path_join()


# implementation

def _unpack_uint32(data):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

_bootstrap_external._r_long()

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What to do with_unpack_uint16?_unpack_uint32 looks to me more descriptive than_r_long.

Copy link
Member

@brettcannonbrettcannonAug 24, 2018
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You can keep_unpack_uint16, I just don't think we need to have two implementations to do the exact same thing of reading in the bytes of a little-endian 4 bytes int. If you don't like the name then feel free to rename it in importlib.

name = name.decode('latin1').translate(cp437_table)

name = name.replace('/', path_sep)
path = f'{archive}{path_sep}{name}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

bootstrap_external._path_join()


def _unpack_uint16(data):
"""Convert 2 bytes in little-endian to an integer."""
assert len(data) == 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nit: Wouldn't be better if we raisedValueError here and in_unpack_uint32()?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

In all cases the length of the data is checked before calling_unpack_uint*(). The assertion condition is always true.

Copy link
Member

@warsawwarsaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Comments just based on reading the code. I'm going to test this branch with importlib_resources (standalone) next.

@@ -0,0 +1,640 @@
'''zipimport provides support for importing Python modules from Zip archives.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Style nit: this should be a""" string.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done.

try:
raw_data = fp.read(data_size)
except OSError:
raise OSError("zipimport: can't read data")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is this just here to change the error message? I guess that's for compatibility with the message raised by the C implementation? I'm not sure how useful that is, and it does kind of hide the original exception (which might be useful for debugging). My inclination is to preserve the originalOSError rather than produce one with a different message, but if you feel otherwise, why not use araise from here too?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Removed the try block.

try:
decompress = _get_decompress_func()
except:
raise ZipImportError("can't decompress data; zlib not available")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

except Exception andraise from

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Addedexcept Exception.

Copy link
Member

@warsawwarsaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The branch does work with importlib_resources AFAICT.

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment:I have made the requested changes; please review again.

@pythonpython deleted a comment fromwarsawSep 11, 2018
Copy link
MemberAuthor

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thank you for your review@warsaw. I have addressed most of your comments. But AFAIKfrom error is not needed in the Python code. Exceptions is chained by default. You need to addfrom None for suppressing chaining.

'PQRSTUVWXYZ[\\]^_'
'`abcdefghijklmno'
'pqrstuvwxyz{|}~\x7f'

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Just for readability. The above part is ASCII, and 16 chars per row, the below part is non-ASCII, and 8 chars per row. What comment should I add?

from zlib import decompress
except:
_bootstrap._verbose_message('zipimport: zlib UNAVAILABLE')
raise ZipImportError("can't decompress data; zlib not available")
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The C implementation catches all exceptions. I agree, that this is evil and will change this.

try:
raw_data = fp.read(data_size)
except OSError:
raise OSError("zipimport: can't read data")
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Removed the try block.

try:
decompress = _get_decompress_func()
except:
raise ZipImportError("can't decompress data; zlib not available")
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Addedexcept Exception.

Copy link
MemberAuthor

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I prefer to make behavior changing clean up and remove unneeded tests in separate PR.

try:
toc_entry = self._files[key]
except KeyError:
raise OSError(0, '', key)
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

For raising a properFileNotFoundError you need to specify the corresponding errno.

importerrnoraiseFileNotFoundError(errno.ENOENT,'No such file or directory',key)

(and maybe usingpathname is more proper thankey).

I prefer to defer this change to later. It is nontrivial and may need additional discussion and tests.

Copy link
Member

@warsawwarsaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think we're down to one issue/question for this branch, a merge conflict, and deferring cleanups to a follow on branch.

Copy link
Member

@warsawwarsaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for doing this - I think it will lead to great improvements in zipimport in the future. My only suggestion would be to open a bpo issue for the subsequent clean up branch, since there are things that we know can be improved on the next pass. I think this is a good change to land.

@serhiy-storchaka
Copy link
MemberAuthor

serhiy-storchaka commentedSep 18, 2018
edited by bedevere-bot
Loading

Thank you for your review@warsaw. I have created two following PRs (#9404 and#9406) and one issue (bpo-34726). Will open more. I still don't know what to do with exceptions.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@berkerpeksagberkerpeksagberkerpeksag left review comments

@benjaminpbenjaminpbenjaminp left review comments

@brettcannonbrettcannonbrettcannon approved these changes

@warsawwarsawwarsaw approved these changes

@Yhg1sYhg1sAwaiting requested review from Yhg1s

Assignees
No one assigned
Labels
DO-NOT-MERGEtype-featureA feature request or enhancement
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

8 participants
@serhiy-storchaka@bedevere-bot@berkerpeksag@brettcannon@warsaw@benjaminp@the-knights-who-say-ni@gpshead

[8]ページ先頭

©2009-2025 Movatter.jp