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

Mark ErrorCodes as serializable #15218

Merged
merged 3 commits into from
May 11, 2023
Merged

Mark ErrorCodes as serializable #15218

merged 3 commits into from
May 11, 2023

Conversation

svalentin
Copy link
Collaborator

When starting mypy daemon, we pickle options. Error codes are part of options and need to be pickle-able. This decorator is needed for this to be possible with mypyc.

Fixes #14671

Valentin Stanciu and others added 2 commits May 10, 2023 15:22
When starting mypy daemon, we pickle options. Error codes are part of
options and need to be pickle-able. This decorator is needed for this to
be possible with mypyc.
@svalentin svalentin requested a review from JukkaL May 10, 2023 22:25
@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks!

@JukkaL JukkaL merged commit 16b5922 into python:master May 11, 2023
@cdce8p
Copy link
Collaborator

cdce8p commented May 12, 2023

This PR seems to cause a new crash with custom plugins - only in compiled mode. I noticed it with pydantic. (Tested with Python 3.11)

pydantic==1.10.7
# config.ini
plugins = pydantic.mypy
# t.py
from pydantic import BaseModel

reveal_type(1)
mypy --config-file=config.ini --show-traceback t.py
Traceback
/.../pydantic/decorator.py:226: 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.4.0+dev.c1fb57d38116adf6c1c1ea5c4b998cae597ec156
Traceback (most recent call last):
  File "mypy/semanal.py", line 6281, in accept
  File "mypy/nodes.py", line 1139, in accept
  File "mypy/semanal.py", line 1574, in visit_class_def
  File "mypy/semanal.py", line 1654, in analyze_class
  File "mypy/semanal.py", line 1681, in analyze_class_body_common
  File "mypy/semanal.py", line 1764, in apply_class_plugin_hooks
  File "/.../pydantic/mypy.py", line 154, in _pydantic_model_class_maker_callback
    transformer.transform()
  File "/.../pydantic/mypy.py", line 313, in transform
    config = self.collect_config()
             ^^^^^^^^^^^^^^^^^^^^^
  File "/.../pydantic/mypy.py", line 360, in collect_config
    config.update(self.get_config_update(substmt))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../pydantic/mypy.py", line 568, in get_config_update
    error_invalid_config_value(lhs.name, self._ctx.api, substmt)
  File "/.../pydantic/mypy.py", line 781, in error_invalid_config_value
    api.fail(f'Invalid value for "Config.{name}"', context, code=ERROR_CONFIG)
  File "mypy/semanal.py", line 6262, in fail
  File "mypy/errors.py", line 436, in report
  File "mypy/errors.py", line 478, in add_error_info
  File "mypy/errors.py", line 577, in is_ignored_error
  File "mypy/errors.py", line 604, in is_error_code_enabled
AttributeError: attribute 'sub_code_of' of 'ErrorCode' undefined
/.../pydantic/decorator.py:226: : note: use --pdb to drop into pdb

From what I can tell, the pydantic plugin always wants to emit an error (which isn't actually shown - this is probably an issue with the plugin itself) but when it calls .fail(...) with a custom ErrorCode mypy crashes. This is the Error Code

ERROR_CONFIG = ErrorCode('pydantic-config', 'Invalid config value', 'Pydantic')

cdce8p added a commit to cdce8p/mypy that referenced this pull request May 12, 2023
@svalentin svalentin deleted the dmypy-win branch May 12, 2023 17:10
cdce8p added a commit to cdce8p/mypy that referenced this pull request May 29, 2023
cdce8p added a commit to cdce8p/mypy that referenced this pull request May 29, 2023
cdce8p added a commit to cdce8p/mypy that referenced this pull request May 29, 2023
cdce8p added a commit to cdce8p/mypy that referenced this pull request May 30, 2023
cdce8p added a commit to cdce8p/mypy that referenced this pull request May 30, 2023
cdce8p added a commit to cdce8p/mypy that referenced this pull request May 30, 2023
cdce8p added a commit to cdce8p/mypy that referenced this pull request May 30, 2023
cdce8p added a commit to cdce8p/mypy that referenced this pull request May 30, 2023
cdce8p added a commit to cdce8p/mypy that referenced this pull request May 30, 2023
cdce8p added a commit to cdce8p/mypy that referenced this pull request May 30, 2023
cdce8p added a commit to cdce8p/mypy that referenced this pull request May 30, 2023
cdce8p added a commit to cdce8p/mypy that referenced this pull request May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Daemon dmypy crashes with disable_error_code configuration option
4 participants