Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
50fda3ba
Commit
50fda3ba
authored
Oct 04, 2001
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make new classes dynamic by default.
parent
ba001a0b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
26 deletions
+24
-26
Misc/NEWS
Misc/NEWS
+10
-0
Objects/typeobject.c
Objects/typeobject.c
+4
-16
PLAN.txt
PLAN.txt
+10
-10
No files found.
Misc/NEWS
View file @
50fda3ba
...
@@ -4,6 +4,16 @@ Release date: 28-Sep-2100
...
@@ -4,6 +4,16 @@ Release date: 28-Sep-2100
Type/class unification and new-style classes
Type/class unification and new-style classes
- New-style classes are now dynamic by default. Previous, they were
static (meaning class attributes could not be assigned to) and
dynamic classes had to be requested by adding __dynamic__ = 1 to the
body of the class or to the module. Static classes are faster than
dynamic classes, but dynamic classes are now at most 50% slower than
static classes; previously, they could be up to 10x slower. (This
was accomplished by making dynamic classes faster, not by making
static classes slower. :-) Note that according to one benchmark,
static classes are about the same speed as classic classes.
- C.__doc__ now works as expected for new-style classes (in 2.2a4 it
- C.__doc__ now works as expected for new-style classes (in 2.2a4 it
always returned None, even when there was a class docstring).
always returned None, even when there was a class docstring).
...
...
Objects/typeobject.c
View file @
50fda3ba
...
@@ -759,9 +759,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
...
@@ -759,9 +759,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
1) in the class dict
1) in the class dict
2) in the module dict (globals)
2) in the module dict (globals)
The first variable that is an int >= 0 is used.
The first variable that is an int >= 0 is used.
Otherwise, a default is calculated from the base classes:
Otherwise, the default is dynamic. */
if any base class is dynamic, this class is dynamic; otherwise
it is static. */
dynamic
=
-
1
;
/* Not yet determined */
dynamic
=
-
1
;
/* Not yet determined */
/* Look in the class */
/* Look in the class */
tmp
=
PyDict_GetItemString
(
dict
,
"__dynamic__"
);
tmp
=
PyDict_GetItemString
(
dict
,
"__dynamic__"
);
...
@@ -783,19 +781,9 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
...
@@ -783,19 +781,9 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
}
}
}
}
if
(
dynamic
<
0
)
{
if
(
dynamic
<
0
)
{
/* Make a new class dynamic if any of its bases is
/* Default to dynamic */
dynamic. This is not always the same as inheriting
dynamic
=
1
;
the __dynamic__ class attribute! */
dynamic
=
0
;
for
(
i
=
0
;
i
<
nbases
;
i
++
)
{
tmptype
=
(
PyTypeObject
*
)
PyTuple_GET_ITEM
(
bases
,
i
);
if
(
tmptype
->
tp_flags
&
Py_TPFLAGS_DYNAMICTYPE
)
{
dynamic
=
1
;
break
;
}
}
}
}
/* Check for a __slots__ sequence variable in dict, and count it */
/* Check for a __slots__ sequence variable in dict, and count it */
...
...
PLAN.txt
View file @
50fda3ba
...
@@ -4,21 +4,18 @@ Project: core implementation
...
@@ -4,21 +4,18 @@ Project: core implementation
Still to do
Still to do
-----------
-----------
Make __dynamic__ the default (this requires more performance work --
More performance work -- one particular test, test_descr.inherits(),
one particular test, test_descr.inherits(), is about 10x slower when
is still about 50% slower with dynamic classes. :-( The approach of
__dynamic__ is 1. :-( There are two ways to go about the performance
choice would be:
work:
a) Add shortcuts to the slot_tp_XXX to recognize a PyWrapperDescr
Add a list of weak refs to derived classes to each dynamic
with the correct wrap_tp_XXX function.
b) Add a list or dict of weak refs to derived classes to each dynamic
class, and trap setattr+delattr on the base class so that they
class, and trap setattr+delattr on the base class so that they
update the tp_XXX slot in each derived class when the base class
update the tp_XXX slot in each derived class when the base class
__XXX__ gets set or deleted. More work, but more gain (zero waste
__XXX__ gets set or deleted. More work, but more gain (zero waste
in slot_tp_XXX when __XXX__ is not overridden).
in slot_tp_XXX when __XXX__ is not overridden). This is currently
awaiting Fred turning the weak ref API into a standard object API.
Add __del__ handlers
.
Add __del__ handlers
?
Allow assignment to __bases__ and __dict__?
Allow assignment to __bases__ and __dict__?
...
@@ -39,6 +36,9 @@ implemented.
...
@@ -39,6 +36,9 @@ implemented.
Done (mostly)
Done (mostly)
-------------
-------------
Make __dynamic__ the default. *** done (but more performance work
needs to be done). ***
Treat all binary operators the same way as I just did for rich
Treat all binary operators the same way as I just did for rich
comparison: in a <op> b, if type(a) is not type(b) and isinstance(b,
comparison: in a <op> b, if type(a) is not type(b) and isinstance(b,
type(a)), try b.__rop__(a) before trying a.__op__(b). *** Done. ***
type(a)), try b.__rop__(a) before trying a.__op__(b). *** Done. ***
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment