1.1 --- a/inspector.py Mon Jan 08 00:13:18 2018 +0100
1.2 +++ b/inspector.py Mon Jan 08 00:30:23 2018 +0100
1.3 @@ -4,7 +4,7 @@
1.4 Inspect and obtain module structure.
1.5
1.6 Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013,
1.7 - 2014, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
1.8 + 2014, 2015, 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -591,11 +591,31 @@
1.13 if is_method and argnames and argnames[0] == "self":
1.14 del argnames[0]
1.15
1.16 + # Convert .name entries in the parameters, provided this is a method.
1.17 +
1.18 + l = []
1.19 + attr_initialisers = []
1.20 +
1.21 + for argname in argnames:
1.22 + if argname[0] == ".":
1.23 + if not is_method:
1.24 + raise InspectError("Attribute initialisers are only allowed amongst method parameters.", function_name, n)
1.25 +
1.26 + argname = argname[1:]
1.27 + attr_initialisers.append(argname)
1.28 +
1.29 + l.append(argname)
1.30 +
1.31 + argnames = l
1.32 +
1.33 # Copy and propagate the parameters.
1.34
1.35 self.importer.function_parameters[function_name] = \
1.36 self.function_parameters[function_name] = argnames[:]
1.37
1.38 + self.importer.function_attr_initialisers[function_name] = \
1.39 + self.function_attr_initialisers[function_name] = attr_initialisers
1.40 +
1.41 # Define all arguments/parameters in the local namespace.
1.42
1.43 locals = \
1.44 @@ -652,8 +672,15 @@
1.45 # Track attribute usage within the namespace.
1.46
1.47 path = self.get_namespace_path()
1.48 + self.start_tracking(locals)
1.49
1.50 - self.start_tracking(locals)
1.51 + # Establish attributes for .name entries, provided this is a method.
1.52 +
1.53 + for argname in attr_initialisers:
1.54 + self.process_assignment_node(
1.55 + compiler.ast.AssAttr(compiler.ast.Name("self"), argname, "OP_ASSIGN"),
1.56 + compiler.ast.Name(argname))
1.57 +
1.58 self.process_structure_node(n.code)
1.59 returns_value = self.stop_tracking()
1.60