microsoft / microsoft/pyright

Type resolution fails for class attributes with Callable[[], None] annotation

Open
#10,728 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

### Bug Summary

Pyright is unable to resolve class attributes annotated with Callable[[], None] (nullary callables) due to the following error: `Could not bind method "" because it is missing a "self" or "cls" parameter (reportAttributeAccessIssue)`.

### Expected Behavior

Class attributes with `Callable[[], None]` annotation should resolve to `() -> None` type signature, consistent with how static methods with no arguments are handled.

### Actual Behavior

Static type checking fails with the following error:

```
% pyright example.py
example.py
example.py:18:11 - error: Cannot access attribute "my_nullary_func" for class "type[TestClass]"
Could not bind method "" because it is missing a "self" or "cls" parameter (reportAttributeAccessIssue)
1 error, 0 warnings, 0 informations
```

### Reproduction Case

```python
from typing import Callable

class TestClass:
my_nullary_func: Callable[[], None] = lambda: None
my_unary_func: Callable[[int], None] = lambda _x: None

@staticmethod
def my_nullary_staticmethod() -> None:
return None

@staticmethod
def my_unary_staticmethod(_x: int) -> None:
return None

# ❌ Resolves to Unknown
TestClass.my_nullary_func

# ✅ Resolves to (int) -> None
TestClass.my_unary_func

# ✅ Resolves to () -> None
TestClass.my_nullary_staticmethod

# ✅ Resolves to (int) -> None
TestClass.my_unary_staticmethod
```

### Environment

Python 3.10.14
macOS Sequoia Version 15.5

Python packages (requirements.txt):
```
nodeenv==1.9.1
nodejs-wheel-binaries==22.17.0
pathspec==0.12.1
pyright==1.1.403
typing_extensions==4.14.1
```

Contributor guide

Open the contributing guide

Research direction

Run the pyright command against the example.py reproduction first, then trace how class attributes annotated with Callable are resolved and bound. Done means TestClass.my_nullary_func resolves as () -> None without the reported error, while the unary callable and staticmethod examples retain their shown signatures.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.