Skip to content

Commit bd0175c

Browse files
committed
Backport to Python 2.2
[SVN r15706]
1 parent 81ffe96 commit bd0175c

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/object/class.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ namespace objects
330330
// rest corresponding to its declared bases.
331331
//
332332
inline object
333-
new_class(char const* name, std::size_t num_types, class_id const* const types)
333+
new_class(char const* name, std::size_t num_types, class_id const* const types, char const* doc)
334334
{
335335
assert(num_types >= 1);
336336

@@ -348,7 +348,12 @@ namespace objects
348348
}
349349

350350
// Call the class metatype to create a new class
351-
object result = object(class_metatype())(module_prefix() + name, bases, dict());
351+
dict d;
352+
353+
if (doc != 0)
354+
d["__doc__"] = doc;
355+
356+
object result = object(class_metatype())(module_prefix() + name, bases, d);
352357
assert(PyType_IsSubtype(result.ptr()->ob_type, &PyType_Type));
353358

354359
if (scope().ptr() != Py_None)
@@ -360,17 +365,14 @@ namespace objects
360365

361366
class_base::class_base(
362367
char const* name, std::size_t num_types, class_id const* const types, char const* doc)
363-
: object(new_class(name, num_types, types))
368+
: object(new_class(name, num_types, types, doc))
364369
{
365370
// Insert the new class object in the registry
366371
converter::registration& converters = const_cast<converter::registration&>(
367372
converter::registry::lookup(types[0]));
368373

369374
// Class object is leaked, for now
370375
converters.class_object = (PyTypeObject*)incref(this->ptr());
371-
372-
if (doc)
373-
this->attr("__doc__") = doc;
374376
}
375377

376378
void class_base::set_instance_size(std::size_t instance_size)

test/defaults.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""
2+
>>> False = 0 # Python 2.2 needs these
3+
>>> True = 1
24
35
>>> from defaults_ext import *
46
>>> bar(1)

0 commit comments

Comments
 (0)