- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: python-best-practices/init-method-required
Language: Python
Severity: Notice
Category: Best Practices
Ensure that a class has an __init__
method. This check is bypassed when the class is a data class (annotated with @dataclass).
class Foo: # need to define __init__
def foo(bar):
pass
def bar(baz):
pass
# dataclass do not require an init class
@dataclass
class Requests:
cpu: float # expressed in cpu cores
memory: int # expressed in bytes
@staticmethod
def from_pod(pod: V1Pod):
cpu = 0.0
memory = 0
for container in pod.spec.containers:
cpu += parse_cpu_string(container.resources.requests["cpu"])
memory += parse_memory_string(container.resources.requests["memory"])
return Requests(cpu, memory)
def add(self, other):
self.cpu += other.cpu
self.memory += other.memory
@frozen
class AnotherClass:
cpu: float
memory: int
def add(self, other):
self.cpu += other.cpu
self.memory += other.memory
class Child(Parent):
def fn():
pass
class AnotherChild(modname.Parent):
def another_fn():
pass
class UserLoginTest(TestCase):
def setUp(self):
self.username = 'testuser'
self.password = 'testpassword'
self.user = User.objects.create_user(username=self.username, password=self.password)
def test_correct_credentials(self):
user = authenticate(username=self.username, password=self.password)
self.assertIsNotNone(user)
self.assertEqual(user, self.user)
def test_incorrect_credentials(self):
user = authenticate(username=self.username, password='wrongpassword')
self.assertIsNone(user)
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
]
operations = [
]
@dataclass
class Foo: # no __init__ required for dataclass
value = 51
class Foo:
def __init__(self):
pass