KEMBAR78
False positive on returning Any from function declared to return object · Issue #8008 · python/mypy · GitHub
Skip to content

False positive on returning Any from function declared to return object #8008

@GoldsteinE

Description

@GoldsteinE

mypy with --warn-return-any gives a warning for this function:

def f() -> object:
    x: Any = 1
    return x

This code is correct in fact: any type is object, so we can safely return Any.
It can be fixed like that:

def f() -> object:
    x: Any = 1
    return cast(object, x)

but cast(object, ...) should be a no-op for mypy IMO.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions