You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setting the disallow-untyped-defs option is set (either through command line flags or mypy.ini) mypy raises errors about requires that an overloaded function's implementation def must also be explicitly annotated. However the documentation / examples for the overload operator in PEP 484 say not to add annotations to this def since its annotation is specified by the overloaded defs (which mypy correctly deduces).
To Reproduce
Run mypy scratch.py --disallow-untyped-defs when scratch.py contains:
from typing import overload
@overload
def foo(value: int) -> int:
pass
@overload
def foo(value: str) -> str:
pass
def foo(value):
pass
# Although this function is unannotated reveal_type(foo) returns:
# note: Revealed type is 'Overload(def (value: builtins.int) -> builtins.int, def (value: builtins.str) -> builtins.str)'
# so mypy is correctly determining the type of foo and so there is no need to annotate it.
Expected Behavior
mypy should reports no errors
Actual Behavior
mypy reports that error: Function is missing a type annotation
Your Environment
Mypy version used: 0.800
Mypy command-line flags: --disallow-untyped-defs
Mypy configuration options from mypy.ini (and other config files):
Python version used: 3.8.5
Operating system and version: Ubuntu 20.04
The text was updated successfully, but these errors were encountered:
Ok, that makes sense and thank you for the link to the other issue. In which case I will submit an issue for updating the examples in the Python overload documentation (for example https://docs.python.org/3/library/typing.html#typing.overload) to reflect the convention of annotating the implementation to allow its body to be type-checked. I think in that example it should be:
Bug Report
Setting the disallow-untyped-defs option is set (either through command line flags or mypy.ini) mypy raises errors about requires that an overloaded function's implementation def must also be explicitly annotated. However the documentation / examples for the overload operator in PEP 484 say not to add annotations to this def since its annotation is specified by the overloaded defs (which mypy correctly deduces).
To Reproduce
Run
mypy scratch.py --disallow-untyped-defs
whenscratch.py
contains:Expected Behavior
mypy should reports no errors
Actual Behavior
mypy reports that
error: Function is missing a type annotation
Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: