hhatto / autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide.
https://pypi.org/project/autopep8/
MIT License
4.54k stars 291 forks source link

imp module is deprecated and will be removed in Python 3.12 #683

Closed hugovk closed 4 months ago

hugovk commented 1 year ago

This project uses the imp module in two examples:

For example:

Python Code

def getmoduleinfo(path):
    """Get the module name, suffix, mode, and module type for a given file."""
    warnings.warn('inspect.getmoduleinfo() is deprecated', DeprecationWarning,
                  2)
    with warnings.catch_warnings():
        warnings.simplefilter('ignore', PendingDeprecationWarning)
        import imp
    filename = os.path.basename(path)
    suffixes = [(-len(suffix), suffix, mode, mtype)
                    for suffix, mode, mtype in imp.get_suffixes()]
    suffixes.sort() # try longest suffixes first, in case they overlap
    for neglen, suffix, mode, mtype in suffixes:
        if filename[neglen:] == suffix:
            return ModuleInfo(filename[:neglen], suffix, mode, mtype)

The imp module is deprecated and set for removal in Python 3.12, due for release in October:

Please update the tests so they will continue working with 3.12.

hhatto commented 4 months ago

This issue has been resolved in autopep8 version 2.1.0.