Skip to content

"object" not callable from functools.partial(print, file=...) #8928

Closed
@mgedmin

Description

@mgedmin

This feels like a bug to me:

import functools
from typing import Optional, TextIO


def report(file: Optional[TextIO]) -> None:
    print_ = functools.partial(print, file=file) if file is not None else print
    print_("hello")

mypy reports

mypy_partial_print.py:7: error: "object" not callable

I would expect it to accept the code.

mypy version is 0.770. git master (commit 273a865) reports the same error.

Note that mypy accepts slight variations, e.g.

def report(file: TextIO) -> None:
    print_ = functools.partial(print, file=file)
    print_("hello")

is fine.

reveal_type(print_) in the original example says it's a builtins.object. It looks like mypy cannot reconcile a function with its own partial application.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions