Title: Crash on forward references in pydantic and django plugins · Issue #18579 · python/mypy · GitHub
Open Graph Title: Crash on forward references in pydantic and django plugins · Issue #18579 · python/mypy
X Title: Crash on forward references in pydantic and django plugins · Issue #18579 · python/mypy
Description: Crash Report Mypy was working fine on my django project until about a week ago, when I started getting this error. I'm not sure what caused it. My python code used to be in the root directory of my project and now I moved it to the backe...
Open Graph Description: Crash Report Mypy was working fine on my django project until about a week ago, when I started getting this error. I'm not sure what caused it. My python code used to be in the root directory of my...
X Description: Crash Report Mypy was working fine on my django project until about a week ago, when I started getting this error. I'm not sure what caused it. My python code used to be in the root directory o...
Opengraph URL: https://github.com/python/mypy/issues/18579
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash on forward references in pydantic and django plugins","articleBody":"**Crash Report**\n\nMypy was working fine on my django project until about a week ago, when I started getting this error. I'm not sure what caused it. My python code used to be in the root directory of my project and now I moved it to the `backend/` directory, and the problem started around then, but I'm not sure whether that is related.\n\nI am using [pre-commit](https://github.com/pre-commit/pre-commit) and have mypy set up in my .pre-commit-config.yaml. The error actually only happens when I run mypy as part of pre-commit. If I just run `mypy .` from the command line, it works fine.\n\nPresently, whenever I run pre-commit, I get an INTERNAL ERROR (details below).\n\n**Traceback**\n\n```\n/home/travis/Repos/bethpage/backend/bethpage/models.py:23: error: INTERNAL ERROR -- Please try using mypy master on GitHub:\nhttps://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build\nPlease report a bug at https://github.com/python/mypy/issues\nversion: 1.16.0+dev.23e2d0f8cbaa2f4874d8f6a6bee3756922c78407\nTraceback (most recent call last):\n File \"/home/travis/Repos/bethpage/.tox/py312/bin/mypy\", line 8, in \u003cmodule>\n sys.exit(console_entry())\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/__main__.py\", line 15, in console_entry\n main()\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/main.py\", line 119, in main\n res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/main.py\", line 203, in run_build\n res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/build.py\", line 191, in build\n result = _build(\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/build.py\", line 267, in _build\n graph = dispatch(sources, manager, stdout)\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/build.py\", line 2937, in dispatch\n process_graph(graph, manager)\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/build.py\", line 3335, in process_graph\n process_stale_scc(graph, scc, manager)\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/build.py\", line 3430, in process_stale_scc\n mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/semanal_main.py\", line 94, in semantic_analysis_for_scc\n process_functions(graph, scc, patches)\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/semanal_main.py\", line 252, in process_functions\n process_top_level_function(\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/semanal_main.py\", line 291, in process_top_level_function\n deferred, incomplete, progress = semantic_analyze_target(\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/semanal_main.py\", line 351, in semantic_analyze_target\n analyzer.refresh_partial(\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/semanal.py\", line 655, in refresh_partial\n self.accept(node)\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/semanal.py\", line 7254, in accept\n node.accept(self)\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/nodes.py\", line 811, in accept\n return visitor.visit_func_def(self)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/semanal.py\", line 913, in visit_func_def\n self.analyze_func_def(defn)\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/semanal.py\", line 958, in analyze_func_def\n self.defer(defn)\n File \"/home/travis/Repos/bethpage/.tox/py312/lib/python3.12/site-packages/mypy/semanal.py\", line 6900, in defer\n assert not self.final_iteration, \"Must not defer during final iteration\"\n ^^^^^^^^^^^^^^^^^^^^^^^^\nAssertionError: Must not defer during final iteration\n/home/travis/Repos/bethpage/backend/bethpage/models.py:23: : note: use --pdb to drop into pdb\n```\n\n**To Reproduce**\n\nThis crash happens any time I change any file in my `backend/` directory and then run `git add -A; pre-commit`.\n\nIt _does not_ happen if I just run `cd backend; mypy .`\n\nIf I use the `--no-incremental` flag or delete the cache directory, the problem still persists.\n\nIf I open up `backend/bethpage/models.py` and add a line that just says \"pass\" somewhere above line 23 (the line cited in the error), then run `git add -A; pre-commit`, it actually works fine and completes without errors. The next time I need to commit something, I'll get the error again, but I can just remove that \"pass\" line and once again, the error goes away.\n\nHere is the beginning of that `/backend/bethpage/models.py` file:\n\n```\nimport uuid\nfrom typing import (\n Any,\n ClassVar,\n Dict,\n Generic,\n Iterable,\n List,\n Mapping,\n Optional,\n Self,\n Tuple,\n TypeVar,\n)\n\nfrom django.db import models, transaction\nfrom django.db.models.fields.reverse_related import ForeignObjectRel\nfrom django.utils import timezone\n\nT = TypeVar(\"T\", bound=\"BaseModel\")\n\n\nclass BaseQuerySet(models.QuerySet[T], Generic[T]):\n\n def bulk_create(self, objs: Iterable[T], *args: Any, **kwargs: Any) -> List[T]:\n for obj in objs:\n obj.full_clean()\n return super().bulk_create(objs, *args, **kwargs)\n...etc...\n```\n\n**Your Environment**\n\n- Mypy version used: I have tried versions of mypy from 1.0.0 to 1.14.1 and have also tried using the master branch on github, always with the same error.\n- Python version used: 3.12\n- Operating system: Arch Linux\n\n.pre-commit-config.yaml\n```\nrepos:\n - repo: local\n hooks:\n - id: mypy\n name: mypy\n entry: mypy\n language: system\n types: [python]\n args:\n - --config-file=backend/mypy.ini\n - --show-traceback\n...etc...\n```\n\nmypy.ini\n```\n[mypy]\npython_version = 3.12\nmypy_path = backend\nplugins =\n mypy_django_plugin.main,\n mypy_drf_plugin.main\nstrict = True\nshow_error_codes = True\ndisallow_untyped_calls = True\ndisallow_untyped_defs = True\ndisallow_incomplete_defs = True\ndisallow_any_unimported = True\ncheck_untyped_defs = True\nno_implicit_optional = True\nwarn_unused_ignores = True\nwarn_return_any = True\nwarn_unreachable = True\n\n[mypy.plugins.django-stubs]\ndjango_settings_module = bethpage.settings\n```","author":{"url":"https://github.com/TravisHardman","@type":"Person","name":"TravisHardman"},"datePublished":"2025-01-31T22:20:13Z","url":"https://github.com/python/mypy/issues/18579"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0fe1e93b-2923-2d57-f7cd-2250b363bad2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8742:1D7BA0:34EAF2:477AD9:6B0027EA |
| html-safe-nonce | 97c878c13accc66454a5103665030a81b9dcbad18749cea7e0573aa81c19481b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzQyOjFEN0JBMDozNEVBRjI6NDc3QUQ5OjZCMDAyN0VBIiwidmlzaXRvcl9pZCI6IjE3NjY0NjA1NDM4NjgwODYyNTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 76ed3ce51d3910b13fd0f592baeea91756e66322d2db3e77a1742ffbc67ed572 |
| hovercard-subject-tag | issue:2824494581 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/18579/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fd3055d14761f6800fb7fcc7dc922afdf8f9a481745ec2b469a590dbb5a82a91/python/mypy/issues/18579 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fd3055d14761f6800fb7fcc7dc922afdf8f9a481745ec2b469a590dbb5a82a91/python/mypy/issues/18579 |
| og:image:alt | Crash Report Mypy was working fine on my django project until about a week ago, when I started getting this error. I'm not sure what caused it. My python code used to be in the root directory of my... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | TravisHardman |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width