Closed
Description
Bug description
from contextlib import AbstractContextManager
from types import TracebackType
from typing import Optional, Type
class Playground(AbstractContextManager["Playground"]):
def __exit__(
self,
exc_type: Optional[Type[BaseException]],
exc_value: Optional[BaseException],
traceback: Optional[TracebackType],
) -> Optional[bool]:
print("closing what needs to be closed")
return None
Configuration
No response
Command used
pylint playground.py
Pylint output
src\playground.py:7:4: R1711: Useless return at end of function or method (useless-return)
Expected behavior
No error message, because without return None
mypy complains:
error: Missing return statement [return]
And mypy swears that they are right, see for example python/mypy#3974
(By the way, the signature from exit was copied from https://mypy.readthedocs.io/en/stable/protocols.html#contextmanager-t)
Pylint version
pylint 2.13.8
astroid 2.11.4
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]
OS / Environment
No response
Additional dependencies
No response