
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.
47 lines
1.3 KiB
Plaintext
47 lines
1.3 KiB
Plaintext
== Why is this an issue?
|
|
|
|
The new style of class creation, with the declaration of a parent class, created a unified object model in Python, so that the type of an instantiated class is equal to its class. In Python 2.2-2.7, this is not the case for old-style classes. In Python 3+ all classes are new-style classes. However, since the behavior can differ from 2.2+ to 3+, explicitly inheriting from ``++object++`` (if there is no better candidate) is recommended.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,python]
|
|
----
|
|
class MyClass():
|
|
pass
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,python]
|
|
----
|
|
class MyClass(object):
|
|
pass
|
|
----
|
|
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Add inheritance from "object" or some other new-style class.
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 15 May 2014, 13:55:35 Pierre-Yves Nicolas wrote:
|
|
In Python 2.x, a class is an old-style class if it does not subclass a new-style class. If a class subclasses another class, we should check recursively whether the superclass is a new-style class. If a class does not subclass any class, we know for sure that it is an old-style class.
|
|
|
|
|
|
See \https://docs.python.org/2/whatsnew/2.2.html#old-and-new-classes
|
|
|
|
endif::env-github,rspecator-view[]
|