Skip to content

False positive for shutil.rmtree for python 3.12 #12103

Closed

Description

@wch

Consider the following file:

import shutil

shutil.rmtree("abcd")

If I run pyright 1.1.366 on it, it reports an error:

❯ pyright --version
pyright 1.1.366
❯ pyright test.py --pythonversion 3.12
/Users/winston/temp/test.py
  /Users/winston/temp/test.py:3:8 - error: The function "rmtree" is deprecated
    The `onerror` parameter is deprecated and will be removed in Python 3.14. Use `onexc` instead. (reportDeprecated)
1 error, 0 warnings, 0 informations 

However, I was not able to reproduce the issue using mypy (the custom typeshed dir was a git clone of this repository at main, b3fc7e2):

❯ mypy --python-version 3.12 --custom-typeshed-dir typeshed test.py
Success: no issues found in 1 source file

I originally filed this issue on the pyright repository (microsoft/pyright#8087), but was told that pyright is working correctly. If that's the case, that would mean it's an issue with shutil.pyi type stub.

Activity

  1. AlexWaygood commented on Jun 6, 2024

    @AlexWaygood
    Member

    I was not able to reproduce the issue using mypy

    Pyright is producing this error because we decorate some overloads of the function with @deprecated. Mypy doesn't support @deprecated yet, so it's expected that it wouldn't produce the same error.

    The onerror parameter for rmtree is indeed deprecated, but python/cpython#112659 removed the deprecation warning at runtime and postponed removal of the parameter indefinitely, on the grounds that the deprecation warnings were too noisy and achieved little (see python/cpython#112645). Given that it is still deprecated, though, maybe we should still continue to use the decorator in the stubs.

    If we do keep it, though, we should apply it in a more intelligent way. Currently you don't even need to pass an argument to onerror for the overload we mark as deprecated to be chosen by the type checker:

    @deprecated("The `onerror` parameter is deprecated and will be removed in Python 3.14. Use `onexc` instead.")

    Thanks for the report! Agree there's a bug here.

  2. AlexWaygood commented on Jun 8, 2024

    @AlexWaygood
    Member

    Looks like this regression was caused by the update in 50cbca4 removing the first overload from rmtree (cc. @Avasam)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: regressionSomething that worked before doesn't work anymorestubs: false positiveType checkers report false errors

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions