Skip to content

Commit ac62db1

Browse files
Anthchirpstefanseefeld
authored andcommitted
Drop injector code example from tutorials.
This example depends on the behaviour of ```__metaclass__```. This has changed in python 3, and the example no longer works. Removing example code as suggested, see boostorg#210 for more details and possible alternatives. Closes boostorg#210.
1 parent b4230e9 commit ac62db1

File tree

1 file changed

+0
-30
lines changed

1 file changed

+0
-30
lines changed

doc/tutorial.qbk

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,36 +1871,6 @@ This technique has several advantages:
18711871
* Minimize the need to recompile
18721872
* Rapid prototyping (you can move the code to C++ if required without changing the interface)
18731873

1874-
You can even add a little syntactic sugar with the use of metaclasses. Let's
1875-
create a special metaclass that "injects" methods in other classes.
1876-
1877-
# The one Boost.Python uses for all wrapped classes.
1878-
# You can use here any class exported by Boost instead of "point"
1879-
BoostPythonMetaclass = point.__class__
1880-
1881-
class injector(object):
1882-
class __metaclass__(BoostPythonMetaclass):
1883-
def __init__(self, name, bases, dict):
1884-
for b in bases:
1885-
if type(b) not in (self, type):
1886-
for k,v in dict.items():
1887-
setattr(b,k,v)
1888-
return type.__init__(self, name, bases, dict)
1889-
1890-
# inject some methods in the point foo
1891-
class more_point(injector, point):
1892-
def __repr__(self):
1893-
return 'Point(x=%s, y=%s)' % (self.x, self.y)
1894-
def foo(self):
1895-
print 'foo!'
1896-
1897-
Now let's see how it got:
1898-
1899-
>>> print point()
1900-
Point(x=10, y=10)
1901-
>>> point().foo()
1902-
foo!
1903-
19041874
Another useful idea is to replace constructors with factory functions:
19051875

19061876
_point = point

0 commit comments

Comments
 (0)