Skip to content

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

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

Closed
mgedmin opened this issue Jun 1, 2020 · 2 comments
Closed

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

mgedmin opened this issue Jun 1, 2020 · 2 comments

Comments

@mgedmin
Copy link
Contributor

mgedmin commented Jun 1, 2020

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.

@mgedmin
Copy link
Contributor Author

mgedmin commented Jun 1, 2020

Hm, this looked different enough from #1484 that I decided to report it as a separate issue, but now I've found #2779 which is similar enough to be a duplicate, and I see that it was closed in favor of #1484.

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 8, 2020

This is basically the same issue as #2779. Closing as duplicate.

@JukkaL JukkaL closed this as completed Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants