Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

59 lines
1.3 KiB
Plaintext

== Why is this an issue?
A class without an explicit extension of object (``++class ClassName(object)++``) is considered an old-style class, and ``++__slots__++`` declarations are ignored in old-style classes. Having such a declaration in an old-style class could be confusing for maintainers and lead them to make false assumptions about the class.
=== Noncompliant code example
[source,python]
----
class A:
__slots__ = ["id"] # Noncompliant; this is ignored
def __init__(self):
self.id = id
self.name = "name" # name wasn't declared in __slots__ but there's no error
a = A()
----
=== Compliant solution
[source,python]
----
class A(object): # Converting to a new-style class is the preferred method of addressing this issue
__slots__ = ["id"]
def __init__(self):
self.id = id
self.name = "name" # "name" is not listed in __slots__, so as expected there is an error in this line
a = A()
----
or
[source,python]
----
class A:
def __init__(self):
self.id = id
self.name = "name"
a = A()
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Either add "(object)" to this class declaration or remove the "__slots__" declaration.
endif::env-github,rspecator-view[]