# HG changeset patch # User Paul Boddie # Date 1515370511 -3600 # Node ID be4f3575f6055179a6349954a34b355654f26169 # Parent 5e73c8cae40cb6de671050b6c4f3e13e07394bfc Added tests for attribute initialisation plus testing for duplicate parameters. diff -r 5e73c8cae40c -r be4f3575f605 inspector.py --- a/inspector.py Mon Jan 08 00:30:23 2018 +0100 +++ b/inspector.py Mon Jan 08 01:15:11 2018 +0100 @@ -604,6 +604,9 @@ argname = argname[1:] attr_initialisers.append(argname) + if argname in l: + raise InspectError("Argument name %s is repeated." % argname, function_name, n) + l.append(argname) argnames = l diff -r 5e73c8cae40c -r be4f3575f605 tests/methods_attr_init.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/methods_attr_init.py Mon Jan 08 01:15:11 2018 +0100 @@ -0,0 +1,24 @@ +class C: + def __init__(.x, .y, .z): # no explicit self, attributes initialised + pass + + def c(): + return self.x + +class D(C): + def d(): + return self.y + +class E(D): + def c(): + return self.z + +c = C(1, 2, 3) +d = D(1, 2, 3) +e = E(1, 2, 3) + +print c.c() # 1 +print d.c() # 1 +print e.c() # 3 +print d.d() # 2 +print e.d() # 2 diff -r 5e73c8cae40c -r be4f3575f605 tests/methods_attr_init_bad.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/methods_attr_init_bad.py Mon Jan 08 01:15:11 2018 +0100 @@ -0,0 +1,24 @@ +class C: + def __init__(.x, .y, .z, x): # no explicit self, attributes initialised + pass + + def c(): + return self.x + +class D(C): + def d(): + return self.y + +class E(D): + def c(): + return self.z + +c = C(1, 2, 3, 4) +d = D(1, 2, 3, 4) +e = E(1, 2, 3, 4) + +print c.c() # 1 +print d.c() # 1 +print e.c() # 3 +print d.d() # 2 +print e.d() # 2