Skip to content

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Sep 9, 2024

Resolves #8029

In order to add type hints to the following Image methods

def __enter__(self):
def _close_fp(self):
def __exit__(self, *args):

I've made a few changes.

Image now has

def __enter__(self) -> Image:
def __exit__(self, *args: object) -> None:

I added an __enter__() and __exit__() to ImageFile, so that with Image.open(...): will type hint an ImageFile instance. I also moved _close_fp() to ImageFile, as it is only used when exiting an ImageFile instance.

def __enter__(self) -> ImageFile:
def _close_fp(self) -> None:
def __exit__(self, *args: object) -> None:

I also moved get_child_images() from Image to ImageFile. It requires the use of self.fp, so this made sense to me, but feel to tell me it should stay in Image.

Believe it or not, all the other changes in this PR flowed out from there.

@hugovk
Copy link
Member

hugovk commented Dec 22, 2024

This is such a big PR I've not found time to review it yet, so let's either ask for reviewers from the community (for example, via #8029), or just go ahead and merge it if you'd like it in the next release.

@radarhere
Copy link
Member Author

I've commented in #8029 asking for reviews, but I'll also try and break this down into smaller PRs, like #8617. The PRs won't help external type hinting by themselves, but they should still individually make sense.

@radarhere radarhere mentioned this pull request Dec 27, 2024
@radarhere radarhere mentioned this pull request Mar 30, 2025
This was referenced Apr 10, 2025
@radarhere radarhere changed the title Added type hints Add type hints Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

py.typed present, but not all methods have types

3 participants