Skip to content

Warn Return Any now applies to small lambdas #9656

Closed
@alanhdu

Description

@alanhdu

Bug Report

Suppose we have the follow code:

from typing import Any

x: Any = [1, 2, 3]
sorted([0, 2, 1], key=lambda i: x[i])

With mypy 0.790, I get an error:

$ mypy --warn-return-any scratch.py
scratch.py:4: error: Returning Any from function declared to return "_SupportsLessThan"
Found 1 error in 1 file (checked 1 source file)

With mypy 0.782, this passes:

$ mypy --warn-return-any scratch.py
Success: no issues found in 1 source file

I'm not actually sure that this is a bug or whether this is an intended feature -- I could see it either way. On one hand, this is technically a case where we are returning any, so warning on this follows the flag name. OTOH though, lambdas are often used for small things where it'd be syntactically cumbersome to add casts.

Your Environment

  • Mypy version used: 0.790
  • Mypy command-line flags: --warn-return-any
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: Python 3.6
  • Operating system and version: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions