From d77be8f86d99826b50e12e5483fda075bc89ad7a Mon Sep 17 00:00:00 2001 From: slateny <46876382+slateny@users.noreply.github.com> Date: Fri, 3 Jun 2022 00:46:46 -0700 Subject: [PATCH 1/4] Clarify import scope in modules tutorial --- Doc/tutorial/modules.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst index d6f2464ae0829c..f326a6b95eb72f 100644 --- a/Doc/tutorial/modules.rst +++ b/Doc/tutorial/modules.rst @@ -84,8 +84,8 @@ refer to its functions, ``modname.itemname``. Modules can import other modules. It is customary but not required to place all :keyword:`import` statements at the beginning of a module (or script, for that -matter). The imported module names are placed in the importing module's global -symbol table. +matter). The imported module names, if placed at the beginning of a module, +are placed in the importing module's global symbol table. There is a variant of the :keyword:`import` statement that imports names from a module directly into the importing module's symbol table. For example:: From 52ac1f8d0c170841a96c2c5a0d5352e9861f391b Mon Sep 17 00:00:00 2001 From: Stanley <46876382+slateny@users.noreply.github.com> Date: Sun, 12 Jun 2022 10:48:49 -0700 Subject: [PATCH 2/4] Use namespace instead of symbol table Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- Doc/tutorial/modules.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst index f326a6b95eb72f..f5fcec08ca9d85 100644 --- a/Doc/tutorial/modules.rst +++ b/Doc/tutorial/modules.rst @@ -84,8 +84,9 @@ refer to its functions, ``modname.itemname``. Modules can import other modules. It is customary but not required to place all :keyword:`import` statements at the beginning of a module (or script, for that -matter). The imported module names, if placed at the beginning of a module, -are placed in the importing module's global symbol table. +matter). The imported module names, if placed at the top level of a module +(outside any functions or classes), are added to the module's global +:term:`namespace` (see :ref:`tut-scopes` for more details). There is a variant of the :keyword:`import` statement that imports names from a module directly into the importing module's symbol table. For example:: From 91ffb42c320972606da3dfeca3d99edd4ac7a785 Mon Sep 17 00:00:00 2001 From: slateny <46876382+slateny@users.noreply.github.com> Date: Tue, 14 Jun 2022 18:07:39 -0700 Subject: [PATCH 3/4] Change all instances of symbol table to namespace --- Doc/tutorial/modules.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst index f5fcec08ca9d85..393dfd220ec03c 100644 --- a/Doc/tutorial/modules.rst +++ b/Doc/tutorial/modules.rst @@ -48,7 +48,8 @@ command:: >>> import fibo This does not enter the names of the functions defined in ``fibo`` directly in -the current symbol table; it only enters the module name ``fibo`` there. Using +the current :term:`namespace` (see :ref:`tut-scopes` for more details); +it only enters the module name ``fibo`` there. Using the module name you can access the functions:: >>> fibo.fib(1000) @@ -75,8 +76,8 @@ These statements are intended to initialize the module. They are executed only the *first* time the module name is encountered in an import statement. [#]_ (They are also run if the file is executed as a script.) -Each module has its own private symbol table, which is used as the global symbol -table by all functions defined in the module. Thus, the author of a module can +Each module has its own private namespace, which is used as the global namespace +by all functions defined in the module. Thus, the author of a module can use global variables in the module without worrying about accidental clashes with a user's global variables. On the other hand, if you know what you are doing you can touch a module's global variables with the same notation used to @@ -85,18 +86,17 @@ refer to its functions, ``modname.itemname``. Modules can import other modules. It is customary but not required to place all :keyword:`import` statements at the beginning of a module (or script, for that matter). The imported module names, if placed at the top level of a module -(outside any functions or classes), are added to the module's global -:term:`namespace` (see :ref:`tut-scopes` for more details). +(outside any functions or classes), are added to the module's global namespace. There is a variant of the :keyword:`import` statement that imports names from a -module directly into the importing module's symbol table. For example:: +module directly into the importing module's namespace. For example:: >>> from fibo import fib, fib2 >>> fib(500) 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 This does not introduce the module name from which the imports are taken in the -local symbol table (so in the example, ``fibo`` is not defined). +local namespace (so in the example, ``fibo`` is not defined). There is even a variant to import all names that a module defines:: @@ -582,4 +582,4 @@ modules found in a package. .. [#] In fact function definitions are also 'statements' that are 'executed'; the execution of a module-level function definition enters the function name in - the module's global symbol table. + the module's global namespace. From c37485fce0588fb354ced7b16f3a1a9465fd7b7e Mon Sep 17 00:00:00 2001 From: Stanley <46876382+slateny@users.noreply.github.com> Date: Tue, 14 Jun 2022 23:19:55 -0700 Subject: [PATCH 4/4] Change 'enters' to 'adds' Co-authored-by: CAM Gerlach --- Doc/tutorial/modules.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst index 393dfd220ec03c..ad70d92994af49 100644 --- a/Doc/tutorial/modules.rst +++ b/Doc/tutorial/modules.rst @@ -47,9 +47,9 @@ command:: >>> import fibo -This does not enter the names of the functions defined in ``fibo`` directly in +This does not add the names of the functions defined in ``fibo`` directly to the current :term:`namespace` (see :ref:`tut-scopes` for more details); -it only enters the module name ``fibo`` there. Using +it only adds the module name ``fibo`` there. Using the module name you can access the functions:: >>> fibo.fib(1000) @@ -581,5 +581,5 @@ modules found in a package. .. rubric:: Footnotes .. [#] In fact function definitions are also 'statements' that are 'executed'; the - execution of a module-level function definition enters the function name in + execution of a module-level function definition adds the function name to the module's global namespace.