blob: 88999f1ccbcc85544b56cec5045c974c267bcee9 [file] [log] [blame]
Tim Peters6d6c1a32001-08-02 04:15:00 +00001Project: core implementation
2****************************
3
Guido van Rossumeb9f3842001-08-30 21:18:04 +00004Still to do
5-----------
Tim Peters6d6c1a32001-08-02 04:15:00 +00006
Guido van Rossum43b9a082001-09-28 18:19:21 +00007Treat all binary operators the same way as I just did for rich
8comparison: in a <op> b, if isinstance(b, type(a)), try b.__rop__(a)
9before trying a.__op__(b).
10
11Make __dynamic__ the default (this requires more performance work --
12one particular test, test_descr.inherits(), is about 10x slower when
13__dynamic__ is 1. :-(
14
15Add __del__ handlers.
16
17Allow assignment to __bases__ and __dict__?
18
19Support mixed multiple inheritance from classic and new-style classes?
20
Guido van Rossumeb9f3842001-08-30 21:18:04 +000021Check for conflicts between base classes. I fear that the rules used
22to decide whether multiple bases have conflicting instance variables
23aren't strict enough. I think that sometimes two different classes
24adding __dict__ may be incompatible after all.
25
26Check for order conflicts. Suppose there are two base classes X and
27Y. Suppose class B derives from X and Y, and class C from Y and X (in
28that order). Now suppose class D derives from B and C. In which
29order should the base classes X and Y be searched? This is an order
30conflict, and should be disallowed; currently the test for this is not
31implemented.
32
Guido van Rossumeb9f3842001-08-30 21:18:04 +000033Done (mostly)
34-------------
35
Guido van Rossumc39553a2001-09-25 06:20:52 +000036Fix comparisons. There's some nasty stuff here: when two types are
37not the same, and they're not instances, the fallback code doesn't
38account for the possibility that they might be subtypes of a common
39base type that defines a comparison. *** I believe this is now done,
40but it's a bit of a mess. ***
41
42Allow __class__ assignment. *** done ***
43
44Change __getattr__ to be more like classic __getattr__, and introduce
45a new name for new-style __getattr__. *** Done. The new-style method
46is called __getattribute__. ***
47
Guido van Rossumed8fa722001-09-20 05:27:24 +000048Make inspect and pydoc do the right thing for new-style classes. ***
49done ***
50
Guido van Rossumeb9f3842001-08-30 21:18:04 +000051Do binary operators properly. nb_add should try to call self.__add__
52and other.__radd__. I think I'll exclude base types that define any
53binary operator without setting the CHECKTYPES flag. *** This is
54done, AFAICT. Even supports __truediv__ and __floordiv__. ***
55
Tim Peters6d6c1a32001-08-02 04:15:00 +000056Fix subtype_dealloc(). This currently searches through the list of
57base types until it finds a type whose tp_dealloc is not
58subtype_dealloc. I think this is not safe. I think the alloc/dealloc
59policy needs to be rethought. *** There's an idea here that I haven't
60worked out yet: just as object creation now has separate API's tp_new,
61tp_alloc, and tp_init, destruction has tp_dealloc and tp_free. (Maybe
62tp_fini should be added to correspond to tp_init?) Something
63could/should be done with this. ***
64
65Clean up isinstance(), issubclass() and their C equivalents. There
66are a bunch of different APIs here and not all of them do the right
67thing yet. There should be fewer APIs and their implementation should
68be simpler. The old "abstract subclass" test should probably
69disappear (if we want to root out ExtensionClass). *** I think I've
70done 90% of this by creating PyType_IsSubtype() and using it
71appropriately. For now, the old "abstract subclass" test is still
72there, and there may be some places where PyObject_IsSubclass() is
73called where PyType_IsSubtype() would be more appropriate. ***
74
Tim Peters6d6c1a32001-08-02 04:15:00 +000075Clean up the GC interface. Currently, tp_basicsize includes the GC
76head size iff tp_flags includes the GC flag bit. This makes object
77size math a pain (e.g. to see if two object types have the same
78instance size, you can't just compare the tp_basicsize fields -- you
79have to conditionally subtract the GC head size). Neil has a patch
80that improves the API in this area, but it's backwards incompatible.
81(http://sf.net/tracker/?func=detail&aid=421893&group_id=5470&atid=305470)
82I think I know of a way to fix the incompatibility (by switching to a
83different flag bit). *** Tim proposed a better idea: macros to access
84tp_basicsize while hiding the nastiness. This is done now, so I think
Guido van Rossumeb9f3842001-08-30 21:18:04 +000085the rest of this task needn't be done. *** *** Neil checked in a
86much improved version of his idea, and it's all squared away. ***
Tim Peters6d6c1a32001-08-02 04:15:00 +000087
88Make the __dict__ of types declared with Python class statements
89writable -- only statically declared types must have an immutable
90dict, because they're shared between interpreter instances. Possibly
91trap writes to the __dict__ to update the corresponding tp_<slot> if
92an __<slot>__ name is affected. *** Done as part of the next task. ***
93
94It should be an option (maybe a different metaclass, maybe a flag) to
95*not* merge __dict__ with all the bases, but instead search the
96__dict__ (or __introduced__?) of all bases in __mro__ order. (This is
97needed anyway to unify classes completely.) *** Partly done.
98Inheritance of slots from bases is still icky: (1) MRO is not always
99respected when inheriting slots; (2) dynamic classes can't add slot
100implementations in Python after creation (e.g., setting C.__hash__
101doesn't set the tp_hash slot). ***
102
103Universal base class (object). How can we make the object class
104subclassable and define simple default methods for everything without
105having these inherited by built-in types that don't want these
106defaults? *** Done, really. ***
107
108Add error checking to the MRO calculation. *** Done. ***
109
110Make __new__ overridable through a Python class method (!). Make more
111of the sub-algorithms of type construction available as methods. ***
112After I implemented class methods, I found that in order to be able
113to make an upcall to Base.__new__() and have it create an instance of
114your class (rather than a Base instance), you can't use class methods
115-- you must use static methods. So I've implemented those too. I've
116hooked up __new__ in the right places, so the first part of this is
117now done. I've also exported the MRO calculation and made it
118overridable, as metamethod mro(). I believe that closes this topic
119for now. I expect that some warts will only be really debugged when
120we try to use this for some, eh, interesting types such as tuples. ***
121
Guido van Rossum04156202001-08-08 16:57:43 +0000122 There was a sequel to the __new__ story (see checkins). There
123 still is a problem: object.__new__ now no longer exists, because
124 it was inherited by certain extension types that could break. But
125 now when I write
126
127 class C(object):
128 def __new__(cls, *args):
129 "How do I call the default __new__ implementation???"
130
Guido van Rossum42a8c2b2001-08-09 20:25:58 +0000131 This was resolved nicely by putting object.__new__ back but not
132 inheriting __new__ from object when the subtype is a built-in or
133 extension type.
134
Tim Peters6d6c1a32001-08-02 04:15:00 +0000135More -- I'm sure new issues will crop up as we go.
136
137
138Project: loose ends and follow-through
139**************************************
140
Guido van Rossumeb9f3842001-08-30 21:18:04 +0000141Still to do
142-----------
Tim Peters6d6c1a32001-08-02 04:15:00 +0000143
144Exceptions should be types. This changes the rules, since now almost
145anything can be raised (as maybe it should). Or should we strive for
146enforcement of the convention that all exceptions should be derived
147from Exception? String exceptions will be another hassle, to be
148deprecated and eventually ruled out.
149
150Standardize a module containing names for all built-in types, and
151standardize on names. E.g. should the official name of the string
152type be 'str', 'string', or 'StringType'?
153
154Create a hierarchy of types, so that e.g. int and long are both
155subtypes of an abstract base type integer, which is itself a subtype
156of number, etc. A lot of thinking can go into this!
157
158*** NEW TASK??? ***
159Implement "signature" objects. These are alluded to in PEP 252 but
160not yet specified. Supposedly they provide an easily usable API to
161find out about function/method arguments. Building these for Python
162functions is simple. Building these for built-in functions will
163require a change to the PyMethodDef structure, so that a type can
164provide signature information for its C methods. (This would also
165help in supporting keyword arguments for C methods with less work than
166PyArg_ParseTupleAndKeywords() currently requires.) But should we do
167this? It's additional work and not required for any of the other
168parts.
169
Guido van Rossumeb9f3842001-08-30 21:18:04 +0000170Done (mostly)
171-------------
172
173Make more (most?) built-in types act as their own factory functions.
174*** Done for all reasonable built-in types. ***
175
176Make more (most?) built-in types subtypable -- with or without
177overridable allocation. *** This includes descriptors! It should be
178possible to write descriptors in Python, so metaclasses can do clever
179things with them. *** *** Done for most reasonable built-in types,
180except for descriptors ***
181
Tim Peters6d6c1a32001-08-02 04:15:00 +0000182
183Project: making classes use the new machinery
184*********************************************
185
186Tasks:
187
188Try to get rid of all code in classobject.c by deferring to the new
189mechanisms. How far can we get without breaking backwards
190compatibility? This is underspecified because I haven't thought much
191about it yet. Can we lose the use of PyInstance_Check() everywhere?
Guido van Rossumeb9f3842001-08-30 21:18:04 +0000192I would hope so! *** I'm dropping this goal for now -- classic
193classes will be 99% unchanged. ***
Tim Peters6d6c1a32001-08-02 04:15:00 +0000194
195
196Project: backwards compatibility
197********************************
198
199Tasks:
200
201Make sure all code checks the proper tp_flags bit before accessing
202type object fields.
203
204Identify areas of incompatibility with Python 2.1. Design solutions.
205Implement and test.
206
207Some specific areas: a fair amount of code probably depends on
208specific types having __members__ and/or __methods__ attributes.
209These are currently not present (conformant to PEP 252, which proposes
210to drop them) but we may have to add them back. This can be done in a
211generic way with not too much effort. Tim adds: Perhaps that dir(object)
212rarely returns anything but [] now is a consequence of this. I'm very
213used to doing, e.g., dir([]) or dir("") in an interactive shell to jog my
214memory; also one of the reasons test_generators failed.
215
216Another area: going all the way with classes and instances means that
217type(x) == types.InstanceType won't work any more to detect instances.
218Should there be a mode where this still works? Maybe this should be
219the default mode, with a warning, and an explicit way to get the new
220way to work? (Instead of a __future__ statement, I'm thinking of a
221module global __metaclass__ which would provide the default metaclass
222for baseless class statements.)
223
224
225Project: testing
226****************
227
228Tasks:
229
230Identify new functionality that needs testing. Conceive unit tests
231for all new functionality. Conceive stress tests for critical
232features. Run the tests. Fix bugs. Repeat until satisfied.
233
234Note: this may interact with the branch integration task.
235
236
Tim Petersf9803012001-08-02 22:06:35 +0000237Project: integration with main branch *** This is done - tim ***
Tim Peters6d6c1a32001-08-02 04:15:00 +0000238*************************************
239
240Tasks:
241
242Merge changes in the HEAD branch into the descr-branch. Then merge
243the descr-branch back into the HEAD branch.
244
245The longer we wait, the more effort this will be -- the descr-branch
246forked off quite a long time ago, and there are changes everywhere in
247the HEAD branch (e.g. the dict object has been radically rewritten).
248
249On the other hand, if we do this too early, we'll have to do it again
250later.
251
252Note from Tim: We should never again wait until literally 100s of files
253are out of synch. I don't care how often I need to do this, provided only
254that it's a tractable task each time. Once per week sounds like a good
255idea. As is, even the trunk change to rangeobject.c created more than its
256proper share of merge headaches, because it confused all the other reasons
257include file merges were getting conflicts (the more changes there are, the
258worse diff does; indeed, I came up with the ndiff algorithm in the 80s
259precisely because the source-control diff program Cray used at the time
260produced minimal but *senseless* diffs, thus creating artificial conflicts;
261paying unbounded attention to context does a much better job of putting
262changes where they make semantic sense too; but we're stuck with Unix diff
263here, and it isn't robust in this sense; if we don't keep its job simple,
264it will make my job hell).
265
266Done:
267To undo or rename before final merge: Modules/spam.c has worked its
268way into the branch Unix and Windows builds (pythoncore.dsp and
269PC/config.c); also imported by test_descr.py. How about renaming to
Tim Petersf9803012001-08-02 22:06:35 +0000270xxsubtype.c (whatever) now? *** this is done - tim ***
Tim Peters6d6c1a32001-08-02 04:15:00 +0000271
272
273Project: performance tuning
274***************************
275
276Tasks:
277
278Pick or create a general performance benchmark for Python. Benchmark
279the new system vs. the old system. Profile the new system. Improve
280hotspots. Repeat until satisfied.
281
282Note: this may interact with the branch integration task.
283
284
285Project: documentation
286**********************
287
288Tasks:
289
290Update PEP 252 (descriptors). Describe more of the prototype
291implementation
292
293Update PEP 253 (subtyping). Complicated architectural wrangling with
294metaclasses. There is an interaction between implementation and
295description.
296
297Write PEP 254 (unification of classes). This should discuss what
298changes for ordinary classes, and how we can make it more b/w
299compatible.
300
301Other documentation. There needs to be user documentation,
302eventually.
303
304
305Project: community interaction
306******************************
307
308Tasks:
309
310Once the PEPs are written, solicit community feedback, and formulate
311responses to the feedback. Give the community enough time to think
312over this complicated proposal. Provide the community with a
313prototype implementation to test. Try to do this *before* casting
314everything in stone!