Skip to content

AttributeError: attribute 'arguments' of 'FuncDef' undefined #11449

Closed

Description

@intgr

Using a development mypy version: 0.920+dev.5703becbbe9be5006ed0d2d998dd4a793f1aedd0

Code similar to:

from typing import Any

from xxx.commands import XxxBaseCommand


class Command(XxxBaseCommand):
    def handle(  # type: ignore[override]
        self,
        a: int,
        b: str,
        c: str,
        *args: Any,
        **options: Any,
    ) -> None:
        pass

Causes an internal error:

Traceback (most recent call last):
  File "mypy/checker.py", line 421, in accept
  File "mypy/nodes.py", line 721, in accept
  File "mypy/checker.py", line 753, in visit_func_def
  File "mypy/checker.py", line 764, in _visit_func_def
  File "mypy/checker.py", line 1457, in check_method_override
  File "mypy/checker.py", line 1485, in check_method_or_accessor_override_for_base
  File "mypy/checker.py", line 1561, in check_method_override_for_base_with_name
  File "mypy/checker.py", line 1723, in check_override
  File "mypy/messages.py", line 839, in signature_incompatible_with_supertype
  File "mypy/messages.py", line 861, in pretty_callable_or_overload
  File "mypy/messages.py", line 1931, in pretty_callable
AttributeError: attribute 'arguments' of 'FuncDef' undefined

I tried to reduce the example, but it cutting it down to a minimal reproducer turned out to be complicated, after some changes it no longer appears. Let me know if you need a better reproducer and I'll see what I can do.

Your Environment

  • Mypy version used: 5703bec
  • Python version used: 3.10.0
  • Operating system and version: macOS

Activity

  1. added
    bugmypy got something wrong
    on Nov 3, 2021
  2. sobolevn commented on Nov 3, 2021

    @sobolevn
    Member

    This might happen because sometimes arguments are deleted from FuncDef:

    mypy/mypy/nodes.py

    Lines 756 to 758 in e324460

    del ret.arguments
    del ret.max_pos
    del ret.min_args

    It might happen after FuncDef is loaded from cache, for example.

  3. domdfcoding commented on Jan 28, 2022

    @domdfcoding
    Contributor

    I too have suddenly started seeing this with mypy 0.931 (Python 3.7 on Ubuntu). Setting incremental = false seems to have stopped the error, so it seems likely to be a caching error.

  4. sobolevn commented on Jan 28, 2022

    @sobolevn
    Member

    @domdfcoding please, report a new issue about your case 🙂
    Reproduction will be very helpful!

  5. added and removed
    bugmypy got something wrong
    on Mar 26, 2022
  6. Zeckie commented on May 18, 2022

    @Zeckie

    I'm getting the same error, and can reproduce with mypy 0.950 (Python 3.10.2, Windows) and the following stubs:

    stubs\foo.pyi

    class Foo:
        def config(self, **foo): ...

    stubs\bar.pyi

    from foo import Foo
    
    class Bar(Foo):
        def config(self, baz: str = ...): ...

    mypy config in pyproject.toml

    [tool.mypy]
    mypy_path = "stubs"

    Command: mypy . --show-traceback

    Output:

    stubs\bar.pyi:4: error: Signature of "config" incompatible with supertype "Foo"
    stubs\bar.pyi:4: note:      Superclass:
    .\stubs\bar.pyi:4: 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: 0.950
    Traceback (most recent call last):
      File "C:\python.install\Python310\lib\runpy.py", line 196, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "C:\python.install\Python310\lib\runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "mypy\checker.py", line 425, in accept
      File "mypy\nodes.py", line 740, in accept
      File "mypy\checker.py", line 776, in visit_func_def
      File "mypy\checker.py", line 787, in _visit_func_def
      File "mypy\checker.py", line 1494, in check_method_override
      File "mypy\checker.py", line 1522, in check_method_or_accessor_override_for_base
      File "mypy\checker.py", line 1608, in check_method_override_for_base_with_name
      File "mypy\checker.py", line 1770, in check_override
      File "mypy\messages.py", line 876, in signature_incompatible_with_supertype
      File "mypy\messages.py", line 898, in pretty_callable_or_overload
      File "mypy\messages.py", line 2019, in pretty_callable
    AttributeError: attribute 'arguments' of 'FuncDef' undefined
    .\stubs\bar.pyi:4: : note: use --pdb to drop into pdb
    

    When run with command mypy --no-incremental ., the output is:

    stubs\bar.pyi:4: error: Signature of "config" incompatible with supertype "Foo"
    stubs\bar.pyi:4: note:      Superclass:
    stubs\bar.pyi:4: note:          def config(self, **foo: Any) -> Any
    stubs\bar.pyi:4: note:      Subclass:
    stubs\bar.pyi:4: note:          def config(self, baz: str = ...) -> Any
    Found 1 error in 1 file (checked 2 source files)
    

    and using master:

    stubs\bar.pyi:4: error: Signature of "config" incompatible with supertype "Foo"
    stubs\bar.pyi:4: note:      Superclass:
    .\stubs\bar.pyi:4: 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: 0.960+dev.74cfa3d46ae6a9c0033bf95d88462619bc3bc044
    Traceback (most recent call last):
      File "C:\python.install\Python310\lib\runpy.py", line 196, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "C:\python.install\Python310\lib\runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "C:\my.venv\Scripts\mypy.exe\__main__.py", line 7, in <module>
        sys.exit(console_entry())
      File "C:\my.venv\lib\site-packages\mypy\__main__.py", line 12, in console_entry
        main(None, sys.stdout, sys.stderr)
      File "C:\my.venv\lib\site-packages\mypy\main.py", line 96, in main
        res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
      File "C:\my.venv\lib\site-packages\mypy\main.py", line 173, in run_build
        res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
      File "C:\my.venv\lib\site-packages\mypy\build.py", line 181, in build
        result = _build(
      File "C:\my.venv\lib\site-packages\mypy\build.py", line 257, in _build
        graph = dispatch(sources, manager, stdout)
      File "C:\my.venv\lib\site-packages\mypy\build.py", line 2755, in dispatch
        process_graph(graph, manager)
      File "C:\my.venv\lib\site-packages\mypy\build.py", line 3113, in process_graph
        process_stale_scc(graph, scc, manager)
      File "C:\my.venv\lib\site-packages\mypy\build.py", line 3220, in process_stale_scc
        if not graph[id].type_check_second_pass():
      File "C:\my.venv\lib\site-packages\mypy\build.py", line 2230, in type_check_second_pass
        return self.type_checker().check_second_pass()
      File "C:\my.venv\lib\site-packages\mypy\checker.py", line 374, in check_second_pass
        self.check_partial(node)
      File "C:\my.venv\lib\site-packages\mypy\checker.py", line 385, in check_partial
        self.accept(node)
      File "C:\my.venv\lib\site-packages\mypy\checker.py", line 430, in accept
        stmt.accept(self)
      File "C:\my.venv\lib\site-packages\mypy\nodes.py", line 748, in accept
        return visitor.visit_func_def(self)
      File "C:\my.venv\lib\site-packages\mypy\checker.py", line 781, in visit_func_def
        self._visit_func_def(defn)
      File "C:\my.venv\lib\site-packages\mypy\checker.py", line 792, in _visit_func_def
        self.check_method_override(defn)
      File "C:\my.venv\lib\site-packages\mypy\checker.py", line 1499, in check_method_override
        if self.check_method_or_accessor_override_for_base(defn, base):
      File "C:\my.venv\lib\site-packages\mypy\checker.py", line 1527, in check_method_or_accessor_override_for_base
        if self.check_method_override_for_base_with_name(defn, name, base):
      File "C:\my.venv\lib\site-packages\mypy\checker.py", line 1613, in check_method_override_for_base_with_name
        self.check_override(typ,
      File "C:\my.venv\lib\site-packages\mypy\checker.py", line 1775, in check_override
        self.msg.signature_incompatible_with_supertype(
      File "C:\my.venv\lib\site-packages\mypy\messages.py", line 845, in signature_incompatible_with_supertype
        self.pretty_callable_or_overload(original, context, offset=ALIGN_OFFSET + 2 * OFFSET,
      File "C:\my.venv\lib\site-packages\mypy\messages.py", line 867, in pretty_callable_or_overload
        self.note(pretty_callable(tp), context,
      File "C:\my.venv\lib\site-packages\mypy\messages.py", line 1979, in pretty_callable
        definition_args = [arg.variable.name for arg in tp.definition.arguments]
    AttributeError: 'FuncDef' object has no attribute 'arguments'
    .\stubs\bar.pyi:4: : note: use --pdb to drop into pdb
    
  7. fperrin commented on May 20, 2022

    @fperrin
    Contributor

    I have a PR open which fixes (I beleive) this issue: #12324

  8. asottile-sentry commented on Jun 13, 2022

    @asottile-sentry

    also hitting this -- a # type: ignore[override] on the line fortunately works around it (or deleting the cache)

  9. AlexWaygood commented on Jun 29, 2022

    @AlexWaygood
    Member

    Should hopefully be fixed by #12324 (let me know if anybody can still reproduce the issue on master!)

  10. nbro10 commented on Sep 19, 2023

    @nbro10

    I was getting this error

    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: 0.950
    Traceback (most recent call last):
      File "mypy/checker.py", line 425, in accept
      File "mypy/nodes.py", line 740, in accept
      File "mypy/checker.py", line 776, in visit_func_def
      File "mypy/checker.py", line 787, in _visit_func_def
      File "mypy/checker.py", line 1494, in check_method_override
      File "mypy/checker.py", line 1522, in check_method_or_accessor_override_for_base
      File "mypy/checker.py", line 1608, in check_method_override_for_base_with_name
      File "mypy/checker.py", line 1770, in check_override
      File "mypy/messages.py", line 876, in signature_incompatible_with_supertype
      File "mypy/messages.py", line 898, in pretty_callable_or_overload
      File "mypy/messages.py", line 2019, in pretty_callable
    AttributeError: attribute 'arguments' of 'FuncDef' undefined
    

    with mypy 0.950, Python 3.8.13, and MacOS Ventura (13.5.1). Deleting the mypy cache (the folder .mypy_cache) seems to have solved the issue, although I have no idea why.

  11. AlexWaygood commented on Sep 19, 2023

    @AlexWaygood
    Member

    with mypy 0.950

    that is a very old version of mypy

  12. nbro10 commented on Sep 19, 2023

    @nbro10

    @AlexWaygood Yes, I know, but there are systems that use old dependencies, and sometimes it's not easy or possible to update them. In our case, we will be updating this dependency soon, but still I wanted to point out the issue still occurs with that mypy version and how I solved it.

    Would be great if someone explained why this issue is even occurring

  13. AlexWaygood commented on Sep 19, 2023

    @AlexWaygood
    Member

    Would be great if someone explained why this issue is even occurring

    there was a bug in mypy's logic for deserialising objects from the mypy cache. the bug was fixed over a year ago in #12324.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions