Skip to content

no error issued when calling a decorated function with the wrong argument type #10704

Closed
@clo-vis

Description

@clo-vis

To Reproduce

Run mypy on this code and then run the code

import functools

@functools.cache
def factorial(n: int) -> int:
    return n * factorial(n-1) if n else 1    

def identity(n: int) -> int:        
    return n

if __name__ == '__main__':
    print(factorial.__name__, factorial.__annotations__)
    print(identity.__name__, identity.__annotations__)
    factorial("")
    identity("")

The output of the program is:

factorial {'n': <class 'int'>, 'return': <class 'int'>}
identity {'n': <class 'int'>, 'return': <class 'int'>}

so type information is available.

Expected Behavior

The lines
factorial("")
and
identity("")
should be both flagged as wrong because the function is called with an incompatible type

Actual Behavior

An error is issued for
identity("")
but not for
factorial("")

As a side note, mypy issues an error

_lru_cache_wrapper[int]" has no attribute "name" for _print(factorial.name, ...)

but this is another issue.

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.9.5
  • Operating system and version: Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-paramspecPEP 612, ParamSpec, Concatenate

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions