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

Deactivate mypy for _functional_pil.py and video_reader.py #8402

Merged
merged 3 commits into from
May 3, 2024

Conversation

NicolasHug
Copy link
Member

Towards #8377

This PR deactivates mypy for _functional_pil.py because it started failing with PIL 10.3 with absurd errors like:

  torchvision/transforms/_functional_pil.py:242: error: Module has no attribute
  "BILINEAR"  [attr-defined]
          interpolation: int = Image.BILINEAR,
                               ^~~~~~~~~~~~~~
  torchvision/transforms/_functional_pil.py:288: error: Module has no attribute
  "NEAREST"  [attr-defined]
          interpolation: int = Image.NEAREST,
                               ^~~~~~~~~~~~~
  torchvision/transforms/_functional_pil.py:297: error: Module has no attribute
  "AFFINE"  [attr-defined]
          return img.transform(output_size, Image.AFFINE, matrix, interpolat...
                                            ^~~~~~~~~~~~
  torchvision/transforms/_functional_pil.py:304: error: Module has no attribute
  "NEAREST"  [attr-defined]
          interpolation: int = Image.NEAREST,
                               ^~~~~~~~~~~~~
  torchvision/transforms/_functional_pil.py:321: error: Module has no attribute
  "BICUBIC"  [attr-defined]
          interpolation: int = Image.BICUBIC,
                               ^~~~~~~~~~~~~
  torchvision/transforms/_functional_pil.py:330: error: Module has no attribute
  "PERSPECTIVE"  [attr-defined]
          return img.transform(img.size, Image.PERSPECTIVE, perspective_coef...

which is not true, PIL.Image does have those attributes, they're just set dynamically at import time (thanks @pmeier for pointing that out!) https://github.com/python-pillow/Pillow/blob/58a47978af9f34851ce926303d05fa677010ce2a/src/PIL/Image.py#L203-L206

This also deactivates mypy for video_reader which is failing with

  torchvision/io/video_reader.py:28: error: Incompatible types in assignment
  (expression has type "ImportError", variable has type Module)  [assignment]
              av = ImportError(
                   ^
  torchvision/io/video_reader.py:38: error: Incompatible types in assignment
  (expression has type "ImportError", variable has type Module)  [assignment]
          av = ImportError(
               ^
  torchvision/io/video_reader.py:200: error: Module has no attribute "EOFError" 
  [attr-defined]
                  except av.error.EOFError:
                         ^~~~~~~~~~~~~~~~~
  torchvision/io/video_reader.py:231: error: Unsupported operand types for /
  ("float" and "None")  [operator]
                  offset = int(round(time_s / temp_str.time_base))
                                     ^
  torchvision/io/video_reader.py:231: note: Right operand is of type "Optional[Fraction]"
  torchvision/io/video_reader.py:254: error: "Stream" has no attribute
  "sample_rate"  [attr-defined]
      ...verage_rate if stream.average_rate is not None else stream.sample_rate
                                                             ^~~~~~~~~~~~~~~~~~
  torchvision/io/video_reader.py:256: error: Unsupported operand types for *
  ("int" and "None")  [operator]
      ...  metadata[stream.type]["duration"].append(float(stream.duration * str...
                                                          ^
  torchvision/io/video_reader.py:256: error: No overload variant of "__rmul__" of
  "Fraction" matches argument type "None"  [operator]
      ...  metadata[stream.type]["duration"].append(float(stream.duration * str...
                                                          ^~~~~~~~~~~~~~~~~~~~~...
  torchvision/io/video_reader.py:256: note: Possible overload variants:
  torchvision/io/video_reader.py:256: note:     def __rmul__(b, Union[int, Fraction], /) -> Fraction
  torchvision/io/video_reader.py:256: note:     def __rmul__(b, float, /) -> float
  torchvision/io/video_reader.py:256: note:     def __rmul__(b, complex, /) -> complex
  torchvision/io/video_reader.py:256: error: Unsupported left operand type for *
  ("None")  [operator]
      ...  metadata[stream.type]["duration"].append(float(stream.duration * str...
                                                          ^~~~~~~~~~~~~~~~~~~~~...
  torchvision/io/video_reader.py:256: note: Both left and right operands are unions

That module will be deprecated soon, so there's no point spending time on it.

Copy link

pytorch-bot bot commented May 3, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/8402

Note: Links to docs will display an error until the docs builds have been completed.

❌ 18 New Failures, 19 Unrelated Failures

As of commit 0f399a7 with merge base 06ad737 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Copy link
Collaborator

@pmeier pmeier left a comment

Choose a reason for hiding this comment

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

LGTM. Static type checks on dynamically set attributes will always be a problem 😕

@NicolasHug NicolasHug merged commit 11db385 into pytorch:main May 3, 2024
9 of 26 checks passed
@NicolasHug NicolasHug deleted the aelfjnlajenfaef branch May 3, 2024 09:43
Copy link

github-actions bot commented May 3, 2024

Hey @NicolasHug!

You merged this PR, but no labels were added.
The list of valid labels is available at https://github.com/pytorch/vision/blob/main/.github/process_commit.py

facebook-github-bot pushed a commit that referenced this pull request May 8, 2024
…y` (#8402)

Reviewed By: vmoens

Differential Revision: D57099466

fbshipit-source-id: 9b0f8c4316c0cc4ad5220d408d060a40e4754792
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.

3 participants