Skip to content

Decorator on __init__ causes loss of type info #5398

@campkeith

Description

@campkeith

Here's a simple example:

from __future__ import annotations
from typing import Callable

def decorator(method: Callable[[Foo], None]) -> Callable[[Foo], None]:
    return method

class Foo():
    @decorator
    def __init__(self):
        pass

reveal_type(Foo.__init__)

The output of mypy is:

% mypy --version
mypy 0.620
% mypy foo.py
foo.py:13: error: Revealed type is 'Any'

This seems to be specific to methods as similar type inferences work fine for functions outside of the class scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions