This page is not yet available in Spanish. We are working on its translation.
If you have any questions or feedback about our current translation project, feel free to reach out to us!

Metadata

ID: python-best-practices/any-type-disallow

Language: Python

Severity: Warning

Category: Error Prone

Description

Use the Any type very carefully. Most of the time, the Any type is used because we do not know exactly what type is being used. If you want to specify that a value can be of any type, use object instead of Any.

Learn More

Non-Compliant Code Examples

my_var: Any = 1
def foo(x: Any):  # do not use Any, use a specific type
   pass

Compliant Code Examples

my_var: int = 1

def my_function(a: str) -> str:
    pass
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis