Skip to content

Odd warning on shutil.rmtree and ExitStack.callback #2105

@warsaw

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

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions