Mercurial > cpython-lru_cache-weakref
annotate Objects/typeobject.c @ 17581:c1937faabb23 2.1
Added support for optional explanation parameter to the \versionadded
macro.
Refactored do_cmd_versionadded() and do_cmd_versionchanged() to do most
of the work in a helper function, with the do_cmd_*() wrappers just supplying
a portion of the replacement text.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Wed, 18 Apr 2001 17:29:14 +0000 |
| parents | 6f6f965c5e2d |
| children | bbac2a6a5d16 |
| rev | line source |
|---|---|
| 145 | 1 |
| 6 | 2 /* Type object implementation */ |
| 3 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
4 #include "Python.h" |
| 6 | 5 |
| 6 /* Type object implementation */ | |
| 7 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
8 static PyObject * |
|
13458
7908ec855665
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
9 type_getattr(PyTypeObject *t, char *name) |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
10 { |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
11 if (strcmp(name, "__name__") == 0) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
12 return PyString_FromString(t->tp_name); |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
13 if (strcmp(name, "__doc__") == 0) { |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
14 char *doc = t->tp_doc; |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
15 if (doc != NULL) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
16 return PyString_FromString(doc); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
17 Py_INCREF(Py_None); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
18 return Py_None; |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
19 } |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
20 if (strcmp(name, "__members__") == 0) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
21 return Py_BuildValue("[ss]", "__doc__", "__name__"); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
22 PyErr_SetString(PyExc_AttributeError, name); |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
23 return NULL; |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
24 } |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
25 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
26 static PyObject * |
|
13458
7908ec855665
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
27 type_repr(PyTypeObject *v) |
| 6 | 28 { |
| 29 char buf[100]; | |
| 30 sprintf(buf, "<type '%.80s'>", v->tp_name); | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
31 return PyString_FromString(buf); |
| 6 | 32 } |
| 33 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
34 PyTypeObject PyType_Type = { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
35 PyObject_HEAD_INIT(&PyType_Type) |
| 6 | 36 0, /* Number of items for varobject */ |
| 37 "type", /* Name of this type */ | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
38 sizeof(PyTypeObject), /* Basic object size */ |
| 6 | 39 0, /* Item size for varobject */ |
| 86 | 40 0, /*tp_dealloc*/ |
|
1051
f54e64c8b9b7
* Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
41 0, /*tp_print*/ |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
42 (getattrfunc)type_getattr, /*tp_getattr*/ |
| 86 | 43 0, /*tp_setattr*/ |
| 44 0, /*tp_compare*/ | |
|
2080
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
45 (reprfunc)type_repr, /*tp_repr*/ |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
46 0, /*tp_as_number*/ |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
47 0, /*tp_as_sequence*/ |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
48 0, /*tp_as_mapping*/ |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
49 0, /*tp_hash*/ |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
50 0, /*tp_call*/ |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
51 0, /*tp_str*/ |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
52 0, /*tp_xxx1*/ |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
53 0, /*tp_xxx2*/ |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
54 0, /*tp_xxx3*/ |
|
c21cc7b3ce28
added getattr(), supporting __doc__ and _name__
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
55 0, /*tp_xxx4*/ |
|
5671
d66304963ca7
American spelling in doc string.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
56 "Define the behavior of a particular type of object.", |
| 6 | 57 }; |
