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

Added type hints #8362

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Sep 9, 2024

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.

src/PIL/ImageFile.py Outdated Show resolved Hide resolved
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.

2 participants