__slots__ should not be a single string

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/slots-no-single-string

Language: Python

Severity: Error

Category: Error Prone

Description

The __slots__ attribute must be a non-string iterable.

Learn More

Non-Compliant Code Examples

class MyClass:
    __slots__ = "attr"  # should be an iterable

    def __init__(self):
        pass

Compliant Code Examples

from django.apps import AppConfig


class TweetsConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'tweets'
class MyClass:
    __slots__ = ("attr", )

    def __init__(self):
        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

PREVIEWING: mervebolat/span-id-preprocessing