-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
"AssertionError: Cannot find component" for local NamedTuple #7281
Comments
This is related to #6422 in the sense that a proper fix for that issues should fix this crash as well. |
Today I was hit by something similar to this (which didn't happen before recreating my tox environment):
This makes mypy unusable for our current project. |
I have something similar where I had this inside pending_download_type = typing.Set[ # pylint: disable=unused-variable
typing.Tuple[QUrl, downloads.AbstractDownloadItem]]
self.pending_downloads = set() # type: pending_download_type and sometimes mypy would crash with:
Usually, rerunning mypy made the issue go away, but sometimes I could trigger it multiple times in a row. I (hopefully) worked around it by doing this: diff --git qutebrowser/browser/webkit/mhtml.py qutebrowser/browser/webkit/mhtml.py
index c45bb802d..abdb4b6ea 100644
--- qutebrowser/browser/webkit/mhtml.py
+++ qutebrowser/browser/webkit/mhtml.py
@@ -244,6 +244,10 @@ class MHTMLWriter:
return msg
+_PendingDownloadType = typing.Set[
+ typing.Tuple[QUrl, downloads.AbstractDownloadItem]]
+
+
class _Downloader:
"""A class to download whole websites.
@@ -264,9 +268,7 @@ class _Downloader:
self.target = target
self.writer = None
self.loaded_urls = {tab.url()}
- pending_download_type = typing.Set[ # pylint: disable=unused-variable
- typing.Tuple[QUrl, downloads.AbstractDownloadItem]]
- self.pending_downloads = set() # type: pending_download_type
+ self.pending_downloads = set() # type: _PendingDownloadType
self._finished_file = False
self._used = False Let me know if I can provide more info in some way - I don't have a minimal reproducer since this only happens sometimes, so it's hard to minimize it down. |
We sometimes get this from mypy: Traceback (most recent call last): [...] File "mypy/main.py", line 89, in main File "mypy/build.py", line 166, in build File "mypy/build.py", line 235, in _build File "mypy/build.py", line 2611, in dispatch File "mypy/build.py", line 2911, in process_graph File "mypy/build.py", line 2989, in process_fresh_modules File "mypy/build.py", line 1919, in fix_cross_refs File "mypy/fixup.py", line 25, in fixup_module File "mypy/fixup.py", line 89, in visit_symbol_table File "mypy/fixup.py", line 45, in visit_type_info File "mypy/fixup.py", line 91, in visit_symbol_table File "mypy/nodes.py", line 874, in accept File "mypy/fixup.py", line 136, in visit_var File "mypy/types.py", line 234, in accept cr_running = gi_running File "mypy/fixup.py", line 169, in visit_type_alias_type File "mypy/fixup.py", line 276, in lookup_qualified_alias File "mypy/fixup.py", line 290, in lookup_qualified File "mypy/fixup.py", line 299, in lookup_qualified_stnode File "mypy/lookup.py", line 47, in lookup_fully_qualified AssertionError: Cannot find component 'pending_download_type' for 'qutebrowser.browser.webkit.mhtml._Downloader.pending_download_type' This seems to help... See: python/mypy#5738 python/mypy#7281
We sometimes get this from mypy: Traceback (most recent call last): [...] File "mypy/main.py", line 89, in main File "mypy/build.py", line 166, in build File "mypy/build.py", line 235, in _build File "mypy/build.py", line 2611, in dispatch File "mypy/build.py", line 2911, in process_graph File "mypy/build.py", line 2989, in process_fresh_modules File "mypy/build.py", line 1919, in fix_cross_refs File "mypy/fixup.py", line 25, in fixup_module File "mypy/fixup.py", line 89, in visit_symbol_table File "mypy/fixup.py", line 45, in visit_type_info File "mypy/fixup.py", line 91, in visit_symbol_table File "mypy/nodes.py", line 874, in accept File "mypy/fixup.py", line 136, in visit_var File "mypy/types.py", line 234, in accept cr_running = gi_running File "mypy/fixup.py", line 169, in visit_type_alias_type File "mypy/fixup.py", line 276, in lookup_qualified_alias File "mypy/fixup.py", line 290, in lookup_qualified File "mypy/fixup.py", line 299, in lookup_qualified_stnode File "mypy/lookup.py", line 47, in lookup_fully_qualified AssertionError: Cannot find component 'pending_download_type' for 'qutebrowser.browser.webkit.mhtml._Downloader.pending_download_type' This seems to help... See: python/mypy#5738 python/mypy#7281
This reverts part of commit 8bcdf4c (zulip#15093), to work around a mypy caching bug: python/mypy#7281. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This reverts part of commit 8bcdf4c (#15093), to work around a mypy caching bug: python/mypy#7281. Signed-off-by: Anders Kaseorg <anders@zulip.com>
I am still having this issue. Any updates? |
I ran into this today. Recursively deleting all of my EDIT: Nevermind, I get the same error again after running |
I'm having this issue as well. Version 0.770. |
Been running into this all the time :/ |
If you declare the |
Seeing the same thing as well, with code like def test_xxx(self) -> None:
class MockXXX(NamedTuple):
x:int |
Also having the same bug with code like: def some_func() ->
class Point(NamedTuple):
x: float
y: float Moving the class outside the function fixed it for me as well. |
mypy was failing sometimes with: ``` AssertionError: Cannot find component '_Result@144' for 'tests.util.test_pep517._Result@144' ``` This is due to a bug: python/mypy#7281 I have applied the workaround suggested in the above issue Full traceback ``` type run-test: commands[1] | mypy tests Traceback (most recent call last): File "/home/user/tox/.tox/type/bin/mypy", line 8, in <module> sys.exit(console_entry()) File "/home/user/tox/.tox/type/lib/python3.9/site-packages/mypy/__main__.py", line 11, in console_entry main(None, sys.stdout, sys.stderr) File "mypy/main.py", line 90, in main File "mypy/build.py", line 179, in build File "mypy/build.py", line 253, in _build File "mypy/build.py", line 2638, in dispatch File "mypy/build.py", line 2955, in process_graph File "mypy/build.py", line 3033, in process_fresh_modules File "mypy/build.py", line 1977, in fix_cross_refs File "mypy/fixup.py", line 26, in fixup_module File "mypy/fixup.py", line 77, in visit_symbol_table File "mypy/fixup.py", line 301, in lookup_qualified_stnode File "mypy/lookup.py", line 47, in lookup_fully_qualified AssertionError: Cannot find component '_Result@144' for 'tests.util.test_pep517._Result@144' ERROR: InvocationError for command /home/user/tox/.tox/type/bin/mypy tests (exited with code 1) ```
sometimes mypy was failing with: ``` AssertionError: Cannot find component '_Result@144' for 'tests.util.test_pep517._Result@144' ``` This is due to a bug: python/mypy#7281 I have applied the workaround suggested in the above issue Full traceback ``` type run-test: commands[1] | mypy tests Traceback (most recent call last): File "/home/user/tox/.tox/type/bin/mypy", line 8, in <module> sys.exit(console_entry()) File "/home/user/tox/.tox/type/lib/python3.9/site-packages/mypy/__main__.py", line 11, in console_entry main(None, sys.stdout, sys.stderr) File "mypy/main.py", line 90, in main File "mypy/build.py", line 179, in build File "mypy/build.py", line 253, in _build File "mypy/build.py", line 2638, in dispatch File "mypy/build.py", line 2955, in process_graph File "mypy/build.py", line 3033, in process_fresh_modules File "mypy/build.py", line 1977, in fix_cross_refs File "mypy/fixup.py", line 26, in fixup_module File "mypy/fixup.py", line 77, in visit_symbol_table File "mypy/fixup.py", line 301, in lookup_qualified_stnode File "mypy/lookup.py", line 47, in lookup_fully_qualified AssertionError: Cannot find component '_Result@144' for 'tests.util.test_pep517._Result@144' ERROR: InvocationError for command /home/user/tox/.tox/type/bin/mypy tests (exited with code 1) ```
this fixes two distinct mypy errors one where NamedTuple/dataclassees can't be defined locally python/mypy#7281 which happens when you run mypy like mypy -p my.core on warm cache the second error is the core/types.py file shadowing the stdlib types module
this fixes two distinct mypy errors one where NamedTuple/dataclassees can't be defined locally python/mypy#7281 which happens when you run mypy like mypy -p my.core on warm cache the second error is the core/types.py file shadowing the stdlib types module
Works around mypy bug python/mypy#7281.
* Improve static typing in bokeh.command * Replace NamedTuple with dataclasses Works around mypy bug python/mypy#7281. * Add dataclasses' helpers * Make a distinction between None and unspecified values * Update and fix unit tests * Simplify the implementation
Running into this today as well. Kind of a bummer as named tuples are a perfect way to declare little local test cases without the overhead of a dataclass |
Clearing the mypy cache appears to fix it, but as soon as the file is edited the error occurs again, it looks like it's because the line number is part of the type? Error:
|
The name of the nested tuple type was inconsistent. Sometimes if was stored using the full name in the module symbol table. Also improve the internal API for creating classes to be less error-prone. Work on #7281.
Don't create `TypeAliasType` for aliases defined within functions, since the target can't be looked up using the full name, as we drop function symbol tables after we've finished processing them. Fixes #7281.
Don't create `TypeAliasType` for aliases defined within functions, since the target can't be looked up using the full name, as we drop function symbol tables after we've finished processing them. Fixes #7281.
A slightly modified version of this test case still crashes on 0.910 and |
When I tried to do |
I've also encountered this issue, and removing the mypy cache resolved. |
* Improve static typing in bokeh.command * Replace NamedTuple with dataclasses Works around mypy bug python/mypy#7281. * Add dataclasses' helpers * Make a distinction between None and unspecified values * Update and fix unit tests * Simplify the implementation
I also had this problem today mypy version is 0.931 and finally solved it using |
@JukkaL Can you reopen this issue? This still occurs. |
Making sure I don't override any existing
|
I am using version 0.991 and this is still happening |
Could you open a new issue with more details and preferably a repro? |
Yes, I'll try to isolate where it is happening and reference this issue in a new one |
I can reproduce it at will with 0.991 in a venv on Debian 11 with this code base, the trigger in my case seems to be addition of Note on (sorry for the heavy and messy codebase for the repro, make sure to follow those exact steps - hoping this will help nevertheless)
|
I'm seeing I think the same or similar issue with
It goes away when I delete Ahh, there's an open issue on |
I'm getting a similar problem
I have to run: Using: |
mypy 0.780 is many, many years old. If you can reproduce on latest, please open a new issue with details. |
I've got an obscure bug which I narrowed down to some cache issues when you have a local class inheriting from
NamedTuple
.Stacktrace:
Easiest to reproduce with the following script (it's crashing on the last mypy invocation)
Most similar issue to this one I found seems to be #2931, but using singleline
NamedTuple
definition (e.g.NT = NamedTuple('NT', [])
) doesn't result in failure, so I figured this is worth separate issue.Using
@dataclass
doesn't result in failure either.I'm using mypy
0.720
. (upd: still happens on0.800
)The text was updated successfully, but these errors were encountered: