__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
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