Skip to content

dmypy + torch: second run produces different results (Final name must be initialized with a value) #17652

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

Closed
randolf-scholz opened this issue Aug 8, 2024 · 0 comments · Fixed by #18906
Labels
bug mypy got something wrong topic-daemon dmypy

Comments

@randolf-scholz
Copy link
Contributor

Today I tried using dmypy for the first time and noticed a really strange bug: the second run produced different results than the first run!
More specifically (and even stranger) the error message "Final name must be initialized with a value" spreads from a known false positive (#5608) to other cases.

To Reproduce

I created a repository with complete repro: https://github.com/randolf-scholz/dmypy_bug
It seems 3 things are relevant:

  1. Using python 3.12.
    (I believe this is because the 3.12 wheel of torch==2.4.0 ships with the py.typed marker, but the 3.11 wheel doesn't)
  2. torch must be imported.
  3. A dataclass using a Final annotation is defined.
minimal working example
__all__ = ["ImmutablePoint", "MyDataClass"]

from typing import Final
from dataclasses import dataclass

import torch

@dataclass
class MyDataClass:
    foo: Final[int]
    bar: Final[int]


class ImmutablePoint:
    x: Final[int]
    y: Final[int]

    def __init__(self, x: int, y: int) -> None:
        super().__init__()
        self.x = x
        self.y = y

Expected Behavior

Subsequent runs should yield the same results.

Actual Behavior

Subsequent spread the error from cases where it is expected to cases where it is not.

$ dmypy start
Daemon started
$ dmypy check src
src/dmypy_final_bug/__init__.py:10: error: Final name must be initialized with a value  [misc]
src/dmypy_final_bug/__init__.py:11: error: Final name must be initialized with a value  [misc]
Found 2 errors in 1 file (checked 1 source file)
$ dmypy check src
src/dmypy_final_bug/__init__.py:10: error: Final name must be initialized with a value  [misc]
src/dmypy_final_bug/__init__.py:11: error: Final name must be initialized with a value  [misc]
src/dmypy_final_bug/__init__.py:15: error: Final name must be initialized with a value  [misc]
src/dmypy_final_bug/__init__.py:16: error: Final name must be initialized with a value  [misc]
Found 4 errors in 1 file (checked 1 source file)

Your Environment

  • python==3.12.4
  • mypy==1.11.1
  • torch==2.4.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-daemon dmypy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants