__slots__ should not be a single string

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