Skip to content

"Missing return statement" caused by context manager? #7577

@jonapich

Description

@jonapich
""" Unit tests. """

from types import TracebackType
from typing import Optional, Type


class TestManager:
    def __enter__(self) -> None:
        ...

    def __exit__(self, exc_type: Optional[Type[BaseException]], 
                 exc_val: Optional[BaseException],
                 exc_tb: Optional[TracebackType]) -> bool:
        ...


def func() -> int:
    with TestManager():
        return 1

Mypy will complain about func(), saying it doesn't have a return statement.

tests/__init__.py:16:1: error: Missing return statement

Is this intended?

Note: I also tried class TestManager(ContextManager[None]): just to see if that would help mypy but it didn't change anything.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions