1.1 --- a/importer.py Sat Feb 04 18:10:20 2017 +0100
1.2 +++ b/importer.py Sat Feb 04 22:26:23 2017 +0100
1.3 @@ -444,6 +444,13 @@
1.4
1.5 if provider and provider != module.name:
1.6
1.7 + # Handle built-in modules accidentally referenced by
1.8 + # names.
1.9 +
1.10 + if provider == "__builtins__" and found.has_kind("<module>"):
1.11 + raise ProgramError("Name %s, used by %s, refers to module %s." %
1.12 + (found.leaf(), module.name, found.get_origin()))
1.13 +
1.14 # Record the provider dependency.
1.15
1.16 module.required.add(provider)
2.1 --- a/referencing.py Sat Feb 04 18:10:20 2017 +0100
2.2 +++ b/referencing.py Sat Feb 04 22:26:23 2017 +0100
2.3 @@ -3,7 +3,7 @@
2.4 """
2.5 Reference abstractions.
2.6
2.7 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
2.8 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
2.9
2.10 This program is free software; you can redistribute it and/or modify it under
2.11 the terms of the GNU General Public License as published by the Free Software
2.12 @@ -187,6 +187,15 @@
2.13
2.14 return self.get_name().rsplit(".", 1)[0]
2.15
2.16 + def leaf(self):
2.17 +
2.18 + "Return the leafname of the reference's origin."
2.19 +
2.20 + if not self.get_origin():
2.21 + return None
2.22 +
2.23 + return self.get_origin().rsplit(".", 1)[-1]
2.24 +
2.25 def ancestors(self):
2.26
2.27 """