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

Crash when defining __post_init__ outside the base-level of a class #16371

Closed
tjkuson opened this issue Oct 30, 2023 · 3 comments
Closed

Crash when defining __post_init__ outside the base-level of a class #16371

tjkuson opened this issue Oct 30, 2023 · 3 comments

Comments

@tjkuson
Copy link

tjkuson commented Oct 30, 2023

Crash Report

Defining a function named __post_init__ anywhere that isn't a class base-level crashes mypy.

Traceback

lmao.py:1: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.6.1
Traceback (most recent call last):
  File "mypy/checker.py", line 585, in accept
  File "mypy/nodes.py", line 790, in accept
  File "mypy/checker.py", line 994, in visit_func_def
  File "mypy/checker.py", line 998, in _visit_func_def
  File "mypy/checker.py", line 1081, in check_func_item
  File "mypy/plugins/dataclasses.py", line 1091, in is_processed_dataclass
AttributeError: attribute 'metadata' of 'TypeInfo' undefined
lmao.py:1: : note: use --pdb to drop into pdb

To Reproduce

Top-level:

def __post_init__(): ...

Nested:

class Foo:
    def func(self):
        def __post_init__(): ...

The following does not cause mypy to crash:

__post_init__ = lambda _: ...

Nor does

class Foo:
    def __post_init__(): ...

Your Environment

  • mypy version used: 1.61
  • Python version used: Reproduced on 3.9 and 3.11
  • Operating system and version: macOS Sonoma 14.1
@AlexWaygood
Copy link
Member

This reproduces with mypy 1.6.1, but is already fixed on the mypy master branch. The fix will be included with mypy 1.7, which should be released soon (see #16341)

@AlexWaygood
Copy link
Member

AlexWaygood commented Oct 30, 2023

(See #16057 and #16080 for the previous issue/PR for regarding this bug :)

@tjkuson
Copy link
Author

tjkuson commented Oct 30, 2023

Thanks for the quick response! Apologies for missing the previous issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants