[v2.3.0]
Added
- #87 Add
--mypy-init-return
to allow omission of a return type hint for__init__
if at least one argument is annotated.
Additional Details
To help provide compatibility with Mypy for maintainers that wish to do so, the --mypy-init-return
flag has been introduced to mimic Mypy's allowance for the omission of return type hints for __init__
methods that are not dynamically typed (at least one argument is annotated). With this flag set, ANN200
level errors will be suppressed for __init__
methods if at least one argument is explicitly annotated.
For example, from Mypy's documentation:
class C1: # Return annotated
def __init__(self) -> None:
self.var = 42
class C2: # Return annotated
def __init__(self, arg: int):
self.var = arg
class C3:
def __init__(self): # Return not annotated
# This body is not type checked
self.var = 42 + 'abc'
NOTE: By default, Mypy does not enforce annotations for self
in class methods, so to completely mimic Mypy's behavior with flake8-annotations
ANN101
will need to be added to the repository's ignored linting codes.
See Mypy's documentation for additional details: https://mypy.readthedocs.io/en/stable/class_basics.html?#annotating-init-methods