Skip to content

False-positive missing-argument when setting method from staticmethod without decorator #2724

@augustfe

Description

@augustfe

Summary

ty reports error[missing-argument] when setting a method in a class from staticmethod(foo). It works as expected when __call__ is set with the @staticmethod decorator. I discovered this behaviour when working with the SymPy v1.14 SingletonRegistry.

Minimal reproduction:

def foo(*args, **kwargs) -> None:
    print("foo", args, kwargs)

class A:
    __call__ = staticmethod(foo)
    bar = staticmethod(foo)

a = A()
a()
a.bar()
a(5)
a.bar(5)
a(x=10)
a.bar(x=10)

Playground link

Result from ty check:

$ uv run ty check test.py
error[missing-argument]: No arguments provided for required parameters `*args`, `**kwargs`
  --> test.py:17:1
   |
16 | a = A()
17 | a()
   | ^^^
18 | a.bar()
   |
info: Union variant `[**_P'return, _R_co'return](**_P'return@staticmethod) -> _R_co'return` is incompatible with this call site
info: Attempted to call union type `A`
info: These arguments are required because `ParamSpec` `_P'return` could represent any set of parameters at runtime
info: rule `missing-argument` is enabled by default

error[missing-argument]: No arguments provided for required parameters `*args`, `**kwargs`
  --> test.py:18:1
  ...

error[missing-argument]: No argument provided for required parameter `**kwargs`
  --> test.py:20:1
  ...
error[missing-argument]: No argument provided for required parameter `**kwargs`
  --> test.py:21:1
  ...
error[missing-argument]: No argument provided for required parameter `*args`
  --> test.py:22:1
  ...
error[missing-argument]: No argument provided for required parameter `*args`
  --> test.py:23:1
  ...

Found 6 diagnostics

Actual behaviour:

$ uv run test.py
foo () {}
foo () {}
foo (5,) {}
foo (5,) {}
foo () {'x': 10}
foo () {'x': 10}

Version

ty 0.0.15

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcallsIssues relating to call-signature checking and diagnosticsgenericsBugs or features relating to ty's generics implementation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions