Edgewall Software

Opened 12 months ago

Last modified 12 months ago

#13603 closed defect

Python 3.12.0b1: shutil.rmtree: DeprecationWarning: onerror argument is deprecated, use onexc instead — at Initial Version

Reported by: Jun Omae Owned by: Jun Omae
Priority: normal Milestone: 1.6
Component: general Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

The following is warned on invoking shutil.rmtree(onerror=...) with Python 3.12.

trac/test.py:555: DeprecationWarning: onerror argument is deprecated, use onexc instead
  shutil.rmtree(path, onerror=onerror)

See also: https://docs.python.org/3.12/library/shutil.html?highlight=onexc#shutil.rmtree

Patch:

  • trac/test.py

    index e6102be75..197b63315 100755
    a b def locate(fn):  
    527527    return None
    528528
    529529
     530if hasattr(inspect, 'getfullargspec'):  # Python 3.11+
     531    _rmtree_argspec = inspect.getfullargspec(shutil.rmtree)
     532    # onexc is added in Python 3.12 and onerror is deprecated
     533    _rmtree_has_onexc = 'onexc' in getattr(_rmtree_argspec, 'kwonlyargs', [])
     534    del _rmtree_argspec
     535else:
     536    _rmtree_has_onexc = False
     537
     538
    530539def rmtree(path):
    531540    def onerror(function, path, excinfo, retry=1):
    532541        # `os.unlink` and `os.remove` fail for a readonly file on Windows.
    def rmtree(path):  
    552561        # Use unicode characters in order to allow non-ansi characters
    553562        # on Windows.
    554563        path = str(path, sys.getfilesystemencoding())
    555     shutil.rmtree(path, onerror=onerror)
     564    kwargs = {'onexc' if _rmtree_has_onexc else 'onerror': onerror}
     565    shutil.rmtree(path, **kwargs)
    556566
    557567
    558568INCLUDE_FUNCTIONAL_TESTS = True

Change History (0)

Note: See TracTickets for help on using tickets.