Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1349437

Browse files
committed
When referring to namespaces, always say "namespaces" instead of
"name spaces". Inconsistency noted by Keith Briggs <[email protected]>.
1 parent 81cccb7 commit 1349437

4 files changed

Lines changed: 54 additions & 53 deletions

File tree

Doc/lib/libdis.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,9 @@ \subsection{Python Byte Code Instructions}
480480

481481
\begin{opcodedesc}{IMPORT_NAME}{namei}
482482
Imports the module \code{co_names[\var{namei}]}. The module object is
483-
pushed onto the stack. The current name space is not affected: for a
483+
pushed onto the stack. The current namespace is not affected: for a
484484
proper import statement, a subsequent \code{STORE_FAST} instruction
485-
modifies the name space.
485+
modifies the namespace.
486486
\end{opcodedesc}
487487

488488
\begin{opcodedesc}{IMPORT_FROM}{namei}

Doc/lib/libfuncs.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ \section{Built-in Functions \label{built-in-funcs}}
227227
The arguments are a file name and two optional dictionaries. The
228228
file is parsed and evaluated as a sequence of Python statements
229229
(similarly to a module) using the \var{globals} and \var{locals}
230-
dictionaries as global and local name space. If the \var{locals}
230+
dictionaries as global and local namespace. If the \var{locals}
231231
dictionary is omitted it defaults to the \var{globals} dictionary.
232232
If both dictionaries are omitted, the expression is executed in the
233233
environment where \function{execfile()} is called. The return value is

Doc/lib/libstdtypes.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ \subsubsection{Functions \label{typesfunctions}}
888888
The implementation adds two special read-only attributes:
889889
\code{\var{f}.func_code} is a function's \dfn{code
890890
object}\obindex{code} (see below) and \code{\var{f}.func_globals} is
891-
the dictionary used as the function's global name space (this is the
891+
the dictionary used as the function's global namespace (this is the
892892
same as \code{\var{m}.__dict__} where \var{m} is the module in which
893893
the function \var{f} was defined).
894894

Doc/tut/tut.tex

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ \subsection{The Interactive Startup File \label{startup}}
317317
This file is only read in interactive sessions, not when Python reads
318318
commands from a script, and not when \file{/dev/tty} is given as the
319319
explicit source of commands (which otherwise behaves like an
320-
interactive session). It is executed in the same name space where
320+
interactive session). It is executed in the same namespace where
321321
interactive commands are executed, so that objects that it defines or
322322
imports can be used without qualification in the interactive session.
323323
You can also change the prompts \code{sys.ps1} and \code{sys.ps2} in
@@ -3236,24 +3236,24 @@ \section{Python Scopes and Name Spaces \label{scopes}}
32363236
32373237
Before introducing classes, I first have to tell you something about
32383238
Python's scope rules. Class definitions play some neat tricks with
3239-
name spaces, and you need to know how scopes and name spaces work to
3239+
namespaces, and you need to know how scopes and namespaces work to
32403240
fully understand what's going on. Incidentally, knowledge about this
32413241
subject is useful for any advanced Python programmer.
32423242
32433243
Let's begin with some definitions.
32443244
3245-
A \emph{name space} is a mapping from names to objects. Most name
3246-
spaces are currently implemented as Python dictionaries, but that's
3247-
normally not noticeable in any way (except for performance), and it
3248-
may change in the future. Examples of name spaces are: the set of
3249-
built-in names (functions such as \function{abs()}, and built-in exception
3250-
names); the global names in a module; and the local names in a
3251-
function invocation. In a sense the set of attributes of an object
3252-
also form a name space. The important thing to know about name
3253-
spaces is that there is absolutely no relation between names in
3254-
different name spaces; for instance, two different modules may both
3255-
define a function ``maximize'' without confusion --- users of the
3256-
modules must prefix it with the module name.
3245+
A \emph{namespace} is a mapping from names to objects. Most
3246+
namespaces are currently implemented as Python dictionaries, but
3247+
that's normally not noticeable in any way (except for performance),
3248+
and it may change in the future. Examples of namespaces are: the set
3249+
of built-in names (functions such as \function{abs()}, and built-in
3250+
exception names); the global names in a module; and the local names in
3251+
a function invocation. In a sense the set of attributes of an object
3252+
also form a namespace. The important thing to know about namespaces
3253+
is that there is absolutely no relation between names in different
3254+
namespaces; for instance, two different modules may both define a
3255+
function ``maximize'' without confusion --- users of the modules must
3256+
prefix it with the module name.
32573257
32583258
By the way, I use the word \emph{attribute} for any name following a
32593259
dot --- for example, in the expression \code{z.real}, \code{real} is
@@ -3262,13 +3262,13 @@ \section{Python Scopes and Name Spaces \label{scopes}}
32623262
\code{modname.funcname}, \code{modname} is a module object and
32633263
\code{funcname} is an attribute of it. In this case there happens to
32643264
be a straightforward mapping between the module's attributes and the
3265-
global names defined in the module: they share the same name
3266-
space!\footnote{
3265+
global names defined in the module: they share the same namespace!
3266+
\footnote{
32673267
Except for one thing. Module objects have a secret read-only
3268-
attribute called \code{__dict__} which returns the dictionary
3269-
used to implement the module's name space; the name
3270-
\code{__dict__} is an attribute but not a global name.
3271-
Obviously, using this violates the abstraction of name space
3268+
attribute called \member{__dict__} which returns the dictionary
3269+
used to implement the module's namespace; the name
3270+
\member{__dict__} is an attribute but not a global name.
3271+
Obviously, using this violates the abstraction of namespace
32723272
implementation, and should be restricted to things like
32733273
post-mortem debuggers.
32743274
}
@@ -3280,54 +3280,54 @@ \section{Python Scopes and Name Spaces \label{scopes}}
32803280
\samp{del modname.the_answer}.
32813281
32823282
Name spaces are created at different moments and have different
3283-
lifetimes. The name space containing the built-in names is created
3283+
lifetimes. The namespace containing the built-in names is created
32843284
when the Python interpreter starts up, and is never deleted. The
3285-
global name space for a module is created when the module definition
3286-
is read in; normally, module name spaces also last until the
3285+
global namespace for a module is created when the module definition
3286+
is read in; normally, module namespaces also last until the
32873287
interpreter quits. The statements executed by the top-level
32883288
invocation of the interpreter, either read from a script file or
32893289
interactively, are considered part of a module called
3290-
\module{__main__}, so they have their own global name space. (The
3290+
\module{__main__}, so they have their own global namespace. (The
32913291
built-in names actually also live in a module; this is called
32923292
\module{__builtin__}.)
32933293
3294-
The local name space for a function is created when the function is
3294+
The local namespace for a function is created when the function is
32953295
called, and deleted when the function returns or raises an exception
32963296
that is not handled within the function. (Actually, forgetting would
32973297
be a better way to describe what actually happens.) Of course,
3298-
recursive invocations each have their own local name space.
3298+
recursive invocations each have their own local namespace.
32993299
3300-
A \emph{scope} is a textual region of a Python program where a name space
3301-
is directly accessible. ``Directly accessible'' here means that an
3302-
unqualified reference to a name attempts to find the name in the name
3303-
space.
3300+
A \emph{scope} is a textual region of a Python program where a
3301+
namespace is directly accessible. ``Directly accessible'' here means
3302+
that an unqualified reference to a name attempts to find the name in
3303+
the namespace.
33043304
33053305
Although scopes are determined statically, they are used dynamically.
33063306
At any time during execution, exactly three nested scopes are in use
3307-
(i.e., exactly three name spaces are directly accessible): the
3307+
(i.e., exactly three namespaces are directly accessible): the
33083308
innermost scope, which is searched first, contains the local names,
33093309
the middle scope, searched next, contains the current module's global
3310-
names, and the outermost scope (searched last) is the name space
3310+
names, and the outermost scope (searched last) is the namespace
33113311
containing built-in names.
33123312
33133313
Usually, the local scope references the local names of the (textually)
33143314
current function. Outside of functions, the local scope references
3315-
the same name space as the global scope: the module's name space.
3316-
Class definitions place yet another name space in the local scope.
3315+
the same namespace as the global scope: the module's namespace.
3316+
Class definitions place yet another namespace in the local scope.
33173317
33183318
It is important to realize that scopes are determined textually: the
3319-
global scope of a function defined in a module is that module's name
3320-
space, no matter from where or by what alias the function is called.
3321-
On the other hand, the actual search for names is done dynamically, at
3322-
run time --- however, the language definition is evolving towards
3323-
static name resolution, at ``compile'' time, so don't rely on dynamic
3324-
name resolution! (In fact, local variables are already determined
3325-
statically.)
3319+
global scope of a function defined in a module is that module's
3320+
namespace, no matter from where or by what alias the function is
3321+
called. On the other hand, the actual search for names is done
3322+
dynamically, at run time --- however, the language definition is
3323+
evolving towards static name resolution, at ``compile'' time, so don't
3324+
rely on dynamic name resolution! (In fact, local variables are
3325+
already determined statically.)
33263326
33273327
A special quirk of Python is that assignments always go into the
33283328
innermost scope. Assignments do not copy data --- they just
33293329
bind names to objects. The same is true for deletions: the statement
3330-
\samp{del x} removes the binding of \code{x} from the name space
3330+
\samp{del x} removes the binding of \code{x} from the namespace
33313331
referenced by the local scope. In fact, all operations that introduce
33323332
new names use the local scope: in particular, import statements and
33333333
function definitions bind the module or function name in the local
@@ -3366,14 +3366,14 @@ \subsection{Class Definition Syntax \label{classDefinition}}
33663366
dictated by the calling conventions for methods --- again, this is
33673367
explained later.
33683368
3369-
When a class definition is entered, a new name space is created, and
3369+
When a class definition is entered, a new namespace is created, and
33703370
used as the local scope --- thus, all assignments to local variables
3371-
go into this new name space. In particular, function definitions bind
3371+
go into this new namespace. In particular, function definitions bind
33723372
the name of the new function here.
33733373
33743374
When a class definition is left normally (via the end), a \emph{class
33753375
object} is created. This is basically a wrapper around the contents
3376-
of the name space created by the class definition; we'll learn more
3376+
of the namespace created by the class definition; we'll learn more
33773377
about class objects in the next section. The original local scope
33783378
(the one in effect just before the class definitions was entered) is
33793379
reinstated, and the class object is bound here to the class name given
@@ -3387,7 +3387,7 @@ \subsection{Class Objects \label{classObjects}}
33873387
33883388
\emph{Attribute references} use the standard syntax used for all
33893389
attribute references in Python: \code{obj.name}. Valid attribute
3390-
names are all the names that were in the class's name space when the
3390+
names are all the names that were in the class's namespace when the
33913391
class object was created. So, if the class definition looked like
33923392
this:
33933393
@@ -3766,9 +3766,10 @@ \section{Private Variables \label{private}}
37663766
when referencing \code{__dict__} directly.
37673767
37683768
Here's an example of a class that implements its own
3769-
\code{__getattr__} and \code{__setattr__} methods and stores all
3770-
attributes in a private variable, in a way that works in Python 1.4 as
3771-
well as in previous versions:
3769+
\method{__getattr__()} and \method{__setattr__()} methods and stores
3770+
all attributes in a private variable, in a way that works in all
3771+
versions of Python, including those available before this feature was
3772+
added:
37723773
37733774
\begin{verbatim}
37743775
class VirtualAttributes:

0 commit comments

Comments
 (0)