Skip to content

Callable[[Any], None]" has no attribute "__defaults__" #11896

Closed
@jpy-git

Description

@jpy-git

Bug Report

mypy produces the false positive Callable[[Any], None]" has no attribute "__defaults__" when code uses the __defaults__ attribute of a function.

To Reproduce

Consider this code:

>>> def foo(a) -> None: pass
>>> print(foo.__defaults__)  # None if no default arguments.
None
>>> def bar(a="abc") -> None: pass
>>> print(bar.__defaults__)  # tuple of default arguments.
("abc",)

Run mypy on a script containing this code and get the false-positive:

test.py:2: error: "Callable[[Any], None]" has no attribute "__defaults__"
test.py:4: error: "Callable[[Any], None]" has no attribute "__defaults__"
Found 2 errors in 1 file (checked 1 source file)

Expected Behavior

No mypy errors since it's a valid attribute of a function.

Actual Behavior

mypy errors shown above.

Your Environment

  • Mypy version used: mypy 0.930
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: Python 3.9.9
  • Operating system and version: MacOS Big Sur

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions