GithubHelp home page GithubHelp logo

Comments (12)

radarhere avatar radarhere commented on September 25, 2024 4

Out of curiosity, I got the current main branch of Pillow and added

[tool.mypy]
disallow_untyped_defs = true

to pyproject.toml. There's quite a lot of untyped defs:

Found 853 errors in 58 files (checked 102 source files)

As a progress update, that number is now halved - we're down to

Found 421 errors in 40 files (checked 102 source files)

from pillow.

radarhere avatar radarhere commented on September 25, 2024 4

We're now down to

Found 97 errors in 16 files (checked 283 source files)

from pillow.

radarhere avatar radarhere commented on September 25, 2024 2

Pillow 10.4.0 has now been released, with type hints for all of the methods explicitly mentioned in this issue.

from pillow.

johnthagen avatar johnthagen commented on September 25, 2024 2

@radarhere 10.4.0 allowed us to remove a lot of type: ignore statements, thanks! ❤️

In our particular codebase, the only remaining untyped call we hit after upgrading to 10.4.0 is:

def __init__(self, image=None, size=None, **kw):

from pillow.

radarhere avatar radarhere commented on September 25, 2024 2

If you're happy with that, great! However, the OP wanted us to meet a different standard - not showing any errors when disallow_untyped_defs = true was enabled.

With that setting, we're still at

Found 57 errors in 11 files (checked 283 source files)

from pillow.

radarhere avatar radarhere commented on September 25, 2024 1

While I don't feel comfortable making the decision to remove py.typed myself, I can help add further type hints. I've created #8030 to add verify(), draft() and _expand() (I think you meant this, as ImageOps.expand() is already typed in 10.3.0).

Edit: I've created #8042 for filter().

#8032 has been created to add type hints for load().

I know that to a certain extent, these were just examples you were mentioning, and there is plenty more work to go.

we call PIL.Image.Image.open() which (among many other function) is untyped

This should already be partially type hinted in 10.3.0.

def open(fp, mode="r", formats=None) -> Image:

Thanks to #7944, that has been improved in main.

Pillow/src/PIL/Image.py

Lines 3250 to 3254 in ddbf08f

def open(
fp: StrOrBytesPath | IO[bytes],
mode: Literal["r"] = "r",
formats: list[str] | tuple[str, ...] | None = None,
) -> ImageFile.ImageFile:

One example of a function missing type hints is from PIL.Image.fromarray.

This has actually already been added to main in #7936

The next release of Pillow is scheduled for July 1st, so if there are any more specific methods you would like to see typed before then, feel free to request them.

from pillow.

radarhere avatar radarhere commented on September 25, 2024 1

#8191 has now typed that method.

from pillow.

johnthagen avatar johnthagen commented on September 25, 2024

We hit a large number of new Mypy issues when we upgraded to Pillow 10.3.0, to the point where we may pin to 10.2.0 until they are addressed and all the missing type hints added (or py.typed is removed until this is done).

Some of the errors can be suppressed in the Mypy config:

[tool.mypy]
untyped_calls_exclude = [
    "PIL",
]

One example of a function missing type hints is PIL.Image.fromarray.

from pillow.

hugovk avatar hugovk commented on September 25, 2024

I'd like to propose a PR, but I'm afraid I don't have the time to work on such a large change. Even the Image class has quite a lot of untyped methods (load(), verify(), draft(), expand(), filter(), and many others).

Smaller PRs are very welcome and also preferred, they're easier to review and quicker to merge.

from pillow.

akx avatar akx commented on September 25, 2024

Looks like

Success: no issues found in 283 source files

to me on 71876cf :)

from pillow.

akx avatar akx commented on September 25, 2024

Ah, I thought we were going with what make mypy checks. My bad!

from pillow.

johnthagen avatar johnthagen commented on September 25, 2024

To avoid regressions, I'd recommend turning this on in this repo once the remaining missing types are fixed.

from pillow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.