1.1 --- a/inspector.py Thu Sep 08 23:06:03 2016 +0200
1.2 +++ b/inspector.py Thu Sep 08 23:34:23 2016 +0200
1.3 @@ -554,9 +554,18 @@
1.4 # Initialise argument and local records.
1.5
1.6 function_name = self.get_object_path(name)
1.7 + argnames = get_argnames(n.argnames)
1.8
1.9 - argnames = self.importer.function_parameters[function_name] = \
1.10 - self.function_parameters[function_name] = get_argnames(n.argnames)
1.11 + # Insert "self" into methods where not explicitly declared.
1.12 +
1.13 + if self.in_class and (not argnames or argnames[0] != "self"):
1.14 + argnames.insert(0, "self")
1.15 +
1.16 + self.importer.function_parameters[function_name] = \
1.17 + self.function_parameters[function_name] = argnames
1.18 +
1.19 + # Define all arguments/parameters in the local namespace.
1.20 +
1.21 locals = self.function_locals[function_name] = {}
1.22
1.23 for argname in argnames:
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/methods.py Thu Sep 08 23:34:23 2016 +0200
2.3 @@ -0,0 +1,26 @@
2.4 +class C:
2.5 + def __init__(self, x, y, z):
2.6 + self.x = x
2.7 + self.y = y
2.8 + self.z = z
2.9 +
2.10 + def c(self):
2.11 + return self.x
2.12 +
2.13 +class D(C):
2.14 + def d(self):
2.15 + return self.y
2.16 +
2.17 +class E(D):
2.18 + def c(self):
2.19 + return self.z
2.20 +
2.21 +c = C(1, 2, 3)
2.22 +d = D(1, 2, 3)
2.23 +e = E(1, 2, 3)
2.24 +
2.25 +result1 = c.c() # 1
2.26 +result2 = d.c() # 1
2.27 +result3 = e.c() # 3
2.28 +result4 = d.d() # 2
2.29 +result5 = e.d() # 2
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tests/methods_selfless.py Thu Sep 08 23:34:23 2016 +0200
3.3 @@ -0,0 +1,26 @@
3.4 +class C:
3.5 + def __init__(x, y, z): # no explicit self
3.6 + self.x = x
3.7 + self.y = y
3.8 + self.z = z
3.9 +
3.10 + def c():
3.11 + return self.x
3.12 +
3.13 +class D(C):
3.14 + def d():
3.15 + return self.y
3.16 +
3.17 +class E(D):
3.18 + def c():
3.19 + return self.z
3.20 +
3.21 +c = C(1, 2, 3)
3.22 +d = D(1, 2, 3)
3.23 +e = E(1, 2, 3)
3.24 +
3.25 +result1 = c.c() # 1
3.26 +result2 = d.c() # 1
3.27 +result3 = e.c() # 3
3.28 +result4 = d.d() # 2
3.29 +result5 = e.d() # 2