Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

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