PyCQA/flake8

E704 false positives with one line overload def

peterjc opened this issue · 2 comments

how did you install flake8?

$ pip install -U flake8

unmodified output of flake8 --bug-report

$ flake8 --bug-report
{
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.10.12",
    "system": "Linux"
  },
  "plugins": [
    {
      "plugin": "flake8-docstrings",
      "version": "1.7.0"
    },
    {
      "plugin": "mccabe",
      "version": "0.7.0"
    },
    {
      "plugin": "pycodestyle",
      "version": "2.11.1"
    },
    {
      "plugin": "pyflakes",
      "version": "3.2.0"
    }
  ],
  "version": "7.0.0"
}

describe the problem

what I expected to happen

This is a test case based on the one in #1575, but formatted with black 24.2.0 which uses a one-line def for the overload type annotation entries:

sample code

# test_case.py
from beartype.typing import Optional, Union, overload

from typing import overload


@overload
def foo() -> None: ...


@overload
def foo(arg: str) -> str: ...


@overload
def foo(arg: int, other_arg: Optional[int]) -> float: ...


def foo(
    arg: Optional[Union[int, str]] = None, other_arg: Optional[int] = None
) -> Optional[Union[float, str]]:
    if arg is None or isinstance(arg, str):
        return arg
    elif isinstance(arg, int) and isinstance(other_arg, int):
        return arg / other_arg
    else:
        assert False, f"unknown type(s) for {arg} and {other_arg}"

commands ran

$ flake8 --select E704 test_case.py
test_case.py:8:1: E704 multiple statements on one line (def)
test_case.py:12:1: E704 multiple statements on one line (def)
test_case.py:16:1: E704 multiple statements on one line (def)

I believe all three E704 entries are false positives, and should be special cased for the combination of @overload and elipsis.

Flake8 orchestrates tools that implement checks. Please re-read the issue template and report this to the appropriate tool

Sigh. Found the right home: PyCQA/pycodestyle#1036

Suggestion to clarify the error code sources: #1922