Skip to content
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

Update UnidentifiedImageError and __version__ imports #7644

Merged
merged 3 commits into from Mar 12, 2024

Conversation

radarhere
Copy link
Member

There are a few instances where UnidentifiedImageError is imported from Image rather than ., and __version__ is imported from . rather than _version.

It would seem better to import items from where they are located, instead of relying on them being imported in another place.

src/PIL/Image.py Outdated
_plugins,
)
from ._binary import i32le, o32be, o32le
from ._util import DeferredError, is_path
from ._version import __version__
Copy link
Member

Choose a reason for hiding this comment

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

Does _version exist solely to simplify version parsing in setup.py? In my opinion, the actual module where the version should be defined is PIL.

Copy link
Member Author

@radarhere radarhere Dec 27, 2023

Choose a reason for hiding this comment

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

It was in setup.py, __init__.py, _imaging.c and appveyor.yml, and #2517 chose to create a new file for it.

It might not be worth making any changes at the moment though, as #7627 has a different plan for the version number.

Copy link
Member

Choose a reason for hiding this comment

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

Let's keep the __version__ import from PIL, as that's the more "official" location (unless we can demonstrate significant performance boost, which I think is unlikely).

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I've pushed a commit so that __version__ is imported from the base instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've created #7874 as a follow up to this, moving the definition of __version__ to __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.

The reason we did this was to be able to import the version without a buildable PIL, so that it could be added to the C build automatically to facilitate the version checks there.

_version.py is a private implementation detail, everyone but setup.py should be referencing the published PIL.__version__ or whatever we're calling it now.

@radarhere radarhere changed the title Import UnidentifiedImageError and __version__ directly Update UnidentifiedImageError and __version__ imports Mar 12, 2024
@hugovk hugovk merged commit 2753057 into python-pillow:main Mar 12, 2024
57 checks passed
@hugovk
Copy link
Member

hugovk commented Mar 12, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants