1 %module python_pythoncode 2 3 // github issue#379 - these examples failed with 3.0.5 and earlier (at least as 4 // far back as 1.3.37): 5 6 struct TYPE { 7 %pythoncode %{ 8 def one(): 9 a = 1 10 # Comment XXXX 11 return a 12 %} 13 }; 14 15 %define %bar 16 %pythoncode %{ 17 def one(): 18 a = 1 19 # 20 return a 21 %} 22 %enddef 23 24 struct TYPE2 { 25 %bar 26 }; 27 28 %{ 29 struct TYPE { }; 30 struct TYPE2 { }; 31 %} 32 33 34 // Overriding __new__ test: https://github.com/swig/swig/pull/1357 35 %inline %{ 36 class Foo { 37 public: 38 virtual ~Foo() {} 39 Foo() {} 40 }; 41 42 Foo* get_foo() {return new Foo();} 43 %} 44 45 %pythoncode %{ 46 print_debug = False 47 %} 48 49 %extend Foo { 50 // Note that %pythoncode is not available with -builtin 51 %pythoncode %{ 52 def __new__(cls, *args, **kwargs): 53 if print_debug: 54 print('in Foo.__new__()') 55 return super(Foo, cls).__new__(cls) 56 57 def __init__(self): 58 if print_debug: 59 print('in Foo.__init__()') 60 %} 61 }; 62