WarningPython Error

DeprecationWarning

DeprecationWarning: function X is deprecated

Traceback

terminal
Traceback (most recent call last):
  File "main.py", line 3, in <module>
    pass
DeprecationWarning: function X is deprecated

What causes this error

A deprecated feature or API was used that will be removed in a future version. The warning provides advance notice to update your code.

How to fix it

Read the warning message for the recommended replacement. Update code to use the new API. Use `python -W default::DeprecationWarning` to see all warnings. Pin dependency versions until migration is complete.

Code that causes this error

Broken
import collections
class MyDict(collections.MutableMapping):  # deprecated
    pass

Fixed code

Fixed
import collections.abc
class MyDict(collections.abc.MutableMapping):
    pass

About DeprecationWarning

A DeprecationWarning is issued when a feature is being used that is scheduled for removal in a future version of Python or a library. These warnings serve as early notifications to developers to update their code before the feature is actually removed. By default, DeprecationWarning is ignored in normal code but shown in test suites and development environments.

To see them in production code, use `python -W default::DeprecationWarning` or configure the `warnings` module. Common examples include using `collections.MutableMapping` instead of `collections.abc.MutableMapping`, using deprecated `distutils` instead of `setuptools`, and calling functions with deprecated parameter names. Libraries typically provide a migration path alongside the deprecation notice.

Addressing deprecation warnings proactively prevents breaking changes when upgrading dependencies or Python itself.

Common scenarios

1

Using deprecated APIs that will be removed in future versions

2

Performing numerical operations that produce inf or NaN values

3

Leaving files, sockets, or connections open without proper cleanup

4

Calling async functions without awaiting the result

Related errors