From 25f00efc279bf52c6cf4aded193e8dd821cd02e2 Mon Sep 17 00:00:00 2001 From: "Eric V. Smith" Date: Thu, 24 May 2012 09:23:31 -0400 Subject: [PATCH] Fix errors found by Nick. --- pep-0420.txt | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/pep-0420.txt b/pep-0420.txt index 2d14ca7b7..3f4175f46 100644 --- a/pep-0420.txt +++ b/pep-0420.txt @@ -324,12 +324,12 @@ Nested namespace packages This example uses the following directory structure:: - Lib/test/namspace_pkgs - parent1 + Lib/test/namespace_pkgs + project1 parent child one.py - parent2 + project2 parent child two.py @@ -342,13 +342,14 @@ Here we add the parent directories to ``sys.path``, and show that the portions are correctly found:: >>> import sys - >>> sys.path += ['Lib/test/namespace_pkgs/parent1/parent', 'Lib/test/namespace_pkgs/parent2/parent'] + >>> sys.path += ['Lib/test/namespace_pkgs/project1', 'Lib/test/namespace_pkgs/project2'] >>> import parent.child.one >>> parent.__path__ - _NamespacePath(['/home/eric/local/python/pep-420/Lib/test/namespace_pkgs/parent1/parent', '/home/eric/local/python/pep-420/Lib/test/namespace_pkgs/parent2/parent']) + _NamespacePath(['Lib/test/namespace_pkgs/project1/parent', 'Lib/test/namespace_pkgs/project2/parent']) >>> parent.child.__path__ - _NamespacePath(['/home/eric/local/python/pep-420/Lib/test/namespace_pkgs/parent1/parent/child', '/home/eric/local/python/pep-420/Lib/test/namespace_pkgs/parent2/parent/child']) + _NamespacePath(['Lib/test/namespace_pkgs/project1/parent/child', 'Lib/test/namespace_pkgs/project2/parent/child']) >>> import parent.child.two + >>> Dynamic path computation ------------------------ @@ -356,16 +357,16 @@ Dynamic path computation This example uses a similar directory structure, but adds a third portion:: - Lib/test/namspace_pkgs - parent1 + Lib/test/namespace_pkgs + project1 parent child one.py - parent2 + project2 parent child two.py - parent3 + project3 parent child three.py @@ -376,21 +377,21 @@ the third portion is then found when it is imported:: # add the first two parent paths to sys.path >>> import sys - >>> sys.path += ['Lib/test/namespace_pkgs/parent1/parent', 'Lib/test/namespace_pkgs/parent2/parent'] + >>> sys.path += ['Lib/test/namespace_pkgs/project1', 'Lib/test/namespace_pkgs/project2'] - # parent.child.one can be imported, because parent1/parent was added to sys.path: + # parent.child.one can be imported, because project1 was added to sys.path: >>> import parent.child.one >>> parent.__path__ - _NamespacePath(['/home/eric/local/python/pep-420/Lib/test/namespace_pkgs/parent1/parent', '/home/eric/local/python/pep-420/Lib/test/namespace_pkgs/parent2/parent']) + _NamespacePath(['Lib/test/namespace_pkgs/project1/parent', 'Lib/test/namespace_pkgs/project2/parent']) - # parent.child.__path__ contains parent1/parent/child and parent2/parent/child, but not parent3/parent/child: + # parent.child.__path__ contains project1/parent/child and project2/parent/child, but not project3/parent/child: >>> parent.child.__path__ - _NamespacePath(['/home/eric/local/python/pep-420/Lib/test/namespace_pkgs/parent1/parent/child', '/home/eric/local/python/pep-420/Lib/test/namespace_pkgs/parent2/parent/child']) + _NamespacePath(['Lib/test/namespace_pkgs/project1/parent/child', 'Lib/test/namespace_pkgs/project2/parent/child']) - # parent.child.two can be imported, because parent2/parent was added to sys.path: + # parent.child.two can be imported, because project2 was added to sys.path: >>> import parent.child.two - # we cannot import parent.child.three, because parent3 is not in the path: + # we cannot import parent.child.three, because project3 is not in the path: >>> import parent.child.three Traceback (most recent call last): File "", line 1, in @@ -399,14 +400,16 @@ the third portion is then found when it is imported:: ImportError: No module named 'parent.child.three' # now add the third parent portion to parent.__path__: - >>> parent.__path__.append('Lib/test/namespace_pkgs/parent3/parent') + >>> parent.__path__.append('Lib/test/namespace_pkgs/project3/parent') + >>> parent.__path__ + _NamespacePath(['Lib/test/namespace_pkgs/project1/parent', 'Lib/test/namespace_pkgs/project2/parent', 'Lib/test/namespace_pkgs/project3/parent']) # and now parent.child.three can be imported: >>> import parent.child.three - # and parent3/parent/child has dynamically been added to parent.child.__path__ + # and project3/parent/child has dynamically been added to parent.child.__path__ >>> parent.child.__path__ - _NamespacePath(['/home/eric/local/python/pep-420/Lib/test/namespace_pkgs/parent1/parent/child', '/home/eric/local/python/pep-420/Lib/test/namespace_pkgs/parent2/parent/child', 'Lib/test/namespace_pkgs/parent3/parent/child']) + _NamespacePath(['Lib/test/namespace_pkgs/project1/parent/child', 'Lib/test/namespace_pkgs/project2/parent/child', 'Lib/test/namespace_pkgs/project3/parent/child']) Discussion