Skip to content

ParamSpec semantics are not correct for generic/overloaded functions #2105

Description

@warsaw

Describe the Bug

Here's the example code:

import shutil
from contextlib import ExitStack


def foo(tmpdir):
    with ExitStack() as resources:
        resources.callback(shutil.rmtree, tmpdir, ignore_errors=True)


def bar(tmpdir):
    shutil.rmtree(tmpdir, ignore_errors=True)

and the output of pyrefly check example.py:

ERROR Missing argument `onerror` in function `contextlib._BaseExitStack.callback` [missing-argument]
 --> example.py:7:27
  |
7 |         resources.callback(shutil.rmtree, tmpdir, ignore_errors=True)
  |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
 INFO 1 error

What's odd to me is that pyrefly complains about onerror (which clearly is a default argument), but only when called through ExitStack.callback. When called explicitly, pyrefly (correctly, IMHO) accepts the call with the missing onerror argument.

% pyrefly --version
pyrefly 0.48.0

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions