Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda as RHS for operator always gets inferred as Any #5843

Open
amarshall opened this issue Oct 26, 2018 · 0 comments
Open

Lambda as RHS for operator always gets inferred as Any #5843

amarshall opened this issue Oct 26, 2018 · 0 comments
Labels
bug mypy got something wrong priority-2-low topic-disallow-any The disallow-any-* family of flags

Comments

@amarshall
Copy link

When a lambda is given as the RHS in an operator (example uses >>, but also occurs with others), the lambda’s type is always inferred as Any. Whereas calling the operator function directly, or passing an explicit function, does not.

from typing import Callable, Generic, TypeVar

_T = TypeVar('_T')
_U = TypeVar('_U')

class A(Generic[_T]):
    _value: _T
    def __init__(self, val: _T) -> None: ...
    def __rshift__(self, f: Callable[[_T], _U]) -> _U: ...

def inc(x: int) -> int: ...

A(1) >> inc  # No error
A(1).__rshift__(lambda x: x + 1)  # No error
A(1) >> (lambda x: x + 1)
#        │         └ Expression has type "Any"
#        └ Expression type contains "Any" (has type Callable[[Any], Any])
  • Python 3.7.0
  • mypy 0.641
  • mypy config:
    [mypy]
    check_untyped_defs = True
    disallow_any_decorated = True
    disallow_any_expr = True
    disallow_any_unimported = True
    disallow_incomplete_defs = True
    disallow_subclassing_any = True
    disallow_untyped_calls = True
    disallow_untyped_decorators = True
    disallow_untyped_defs = True
    warn_return_any = True
    warn_unused_ignores = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-2-low topic-disallow-any The disallow-any-* family of flags
Projects
None yet
Development

No branches or pull requests

3 participants