Skip to content

Commit 1311089

Browse files
committed
📝 Update glossary
* Add constant, singleton and immutable objects
1 parent 9d0d5ff commit 1311089

File tree

16 files changed

+70
-52
lines changed

16 files changed

+70
-52
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Added
3232
Changed
3333
~~~~~~~
3434

35+
* 📝 Update glossary
36+
37+
* Add constant, singleton and immutable objects
38+
3539
* 📝 Update uv sections
3640

3741
* Reproducing and updating uv environments

docs/appendix/glossary.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ Glossary
1616
at the beginning of an argument list and/or passed as elements of an
1717
iteration preceded by ``*``.
1818

19+
20+
Constant
21+
Python has :term:`immutable` objects, but no constant variables.
22+
Variables refer to objects, but there is no way to prevent a new
23+
assignment from being made.
24+
1925
Control flow
2026
Time sequence of the individual commands of a computer program.
2127

@@ -95,6 +101,11 @@ Glossary
95101
.. seealso::
96102
* :py:mod:`gc`
97103

104+
Immutable
105+
An object that cannot be mutated. The value of an immutable object cannot
106+
change. :doc:`Tuples <../types/sequences-sets/tuples>` are examples of
107+
immutable objects.
108+
98109
LBYL
99110
Look before you leap. With this style, the preconditions are explicitly
100111
checked before the call. This style is in contrast to the :term:`EAFP`
@@ -111,6 +122,10 @@ Glossary
111122
.. seealso::
112123
* :doc:`/functions/params`
113124

125+
Singleton object
126+
A singleton class can only create one instance of itself.
127+
:doc:`../types/none` is an example of a singleton class in Python.
128+
114129
Zen of Python
115130
Listing of Python design principles and philosophies that are helpful for
116131
understanding and using the language. The list can be output by entering
@@ -459,7 +474,6 @@ Glossary
459474
* `GitHub <https://github.com/scikit-build/scikit-build>`__
460475
* `PyPI <https://pypi.org/project/scikit-build>`__
461476

462-
463477
setuptools
464478
setuptools are the classic build system, which is very powerful, but with
465479
a steep learning curve and high configuration effort. From version

docs/control-flow/boolean.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ considered ``True``.
5353
If ``x`` and ``z[0]`` have the same ID in memory, this means that we are
5454
referring to the same object in two places.
5555

56-
Most frequently, ``is`` and ``is not`` are used in conjunction with
57-
:doc:`../types/none`:
56+
The ``is`` operator is mostly used for values that only exist once in
57+
memory, so-called :term:`singleton objects <Singleton object>`. For example,
58+
checking for :doc:`../types/none` is the most common use of the ``is``
59+
operator.
5860

5961
.. code-block:: pycon
6062
@@ -63,9 +65,9 @@ considered ``True``.
6365
>>> x is not None
6466
True
6567
66-
The Python style guide in :pep:`8` says that you should use identity to
67-
compare with :doc:`../types/none`. So you should never use ``x == None``,
68-
but ``x is None`` instead.
68+
The Python style guide in :pep:`8` also recommends that you should check for
69+
identity with :doc:`../types/none` and not for values, so never use ``x ==
70+
None``, but always use ``x is None`` instead.
6971

7072
``and``, ``not``, ``or``
7173
are logical operators that we can use to link the above checks:

docs/functions/params.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Mutable objects as arguments
224224
----------------------------
225225

226226
Arguments are passed by object reference. The parameter becomes a new reference
227-
to the object. With immutable objects such as
227+
to the object. With :term:`immutable` objects such as
228228
:doc:`/types/sequences-sets/tuples`, :doc:`/types/strings/index` and
229229
:doc:`/types/numbers/index`, what is done with a parameter has no effect
230230
outside the function. However, if you pass a mutable object, such as a
@@ -244,7 +244,7 @@ function. Reassigning the parameter has no effect on the argument.
244244
>>> x, y
245245
(5, [2, 4, 6, 1])
246246
247-
The variable ``x`` is not changed because it is unchangeable. Instead, the
247+
The variable ``x`` is not changed because it is :term:`immutable`. Instead, the
248248
function parameter ``n`` is set so that it refers to the new value ``6``.
249249
However, there is a change in ``y`` because the list it refers to has been
250250
changed.

docs/libs/batteries.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
======================
33

44
In Python, a library can consist of several components, including built-in data
5-
types and constants that can be used without an import statement, such as
5+
types and variables that can be used without an import statement, such as
66
:doc:`/types/numbers/index` and :doc:`/types/sequences-sets/lists`, as well as
77
some built-in :doc:`/functions/index` and :doc:`/control-flow/exceptions`. The
88
largest part of the library is an extensive collection of :doc:`/modules/index`.

docs/packs/distribution.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ directory.
340340

341341
:file:`loaders.py`
342342
is an example of a module within the package that could contain the logic
343-
(functions, classes, constants, :abbr:`etc. (et cetera)`) of your package.
343+
(functions, classes, variables, :abbr:`etc. (et cetera)`) of your package.
344344

345345
Other files
346346
-----------

docs/save-data/filesystem.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ has a separate root directory for each drive, referred to as :samp:`{C:\\}`, and
2626
so on. Because of these differences, files have different path names on
2727
different operating systems. A file named :samp:`{C:\\DATA\\MYFILE}` on Windows
2828
could be :samp:`{/DATA/MYFILE}` on Linux and macOS. Python provides functions
29-
and constants that allow you to perform common pathname manipulations without
29+
and variables that allow you to perform common pathname manipulations without
3030
having to worry about such syntactical details. With a little care, you can
3131
write your Python programs to run correctly regardless of the underlying file
3232
system.
@@ -109,12 +109,12 @@ Relative pathnames
109109
110110
.. note::
111111
``os.getcwd()`` is used as a function call without arguments to make it
112-
clear that the returned value is not a constant, but changes when you
113-
change the value of the current working directory. In the example
114-
above, the result is the home directory on one of my Linux machines. On
115-
Windows machines, additional backslashes would be added to the path:
116-
``C:\\Users\\Veit``, because Windows uses the backslash ``\`` as a path
117-
separator, but it has a different meaning in
112+
clear that the returned value is not a :term:`constant`, but changes
113+
when you change the value of the current working directory. In the
114+
example above, the result is the home directory on one of my Linux
115+
machines. On Windows machines, additional backslashes would be added to
116+
the path: ``C:\\Users\\Veit``, because Windows uses the backslash ``\``
117+
as a path separator, but it has a different meaning in
118118
:doc:`/types/strings/index`.
119119

120120
To display the contents of the current directory, you can enter the
@@ -244,7 +244,7 @@ operating system-specific syntax.
244244
>>> os.path.expandvars("$HOME/python-basics-tutorial")
245245
'/home/veit/python-basics-tutorial'
246246
247-
Useful constants and functions
247+
Useful variables and functions
248248
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
249249

250250
:data:`python3:os.name`

docs/style.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ Python conventions can be found in the following table:
6767
+-----------------------+-------------------------------+-------------------------------+
6868
| Class names | CamelCase notation | ``MyClass`` |
6969
+-----------------------+-------------------------------+-------------------------------+
70-
| Constant names | Capital letters with | ``PI`` |
71-
| | underscores | |
70+
| :term:`Constant` | Capital letters with | ``PI`` |
71+
| names | underscores | |
7272
+-----------------------+-------------------------------+-------------------------------+
7373
| Indentation | Four spaces per level, no | |
7474
| | tabs | |

docs/types/numbers/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Advanced numerical functions
112112
----------------------------
113113

114114
More advanced numerical functions such as trigonometry, as well as some useful
115-
constants, are not built into Python, but are provided in a standard module
115+
variables, are not built into Python, but are provided in a standard module
116116
called :doc:`math <python3:library/math>`. :doc:`Module </modules/index>` will
117117
be explained in more detail later. For now, suffice it to say that you need to
118118
make the maths functions available in this section by importing ``math``:
@@ -153,7 +153,7 @@ The ``math`` module provides, among other things
153153
:func:`python3:math.sin`,
154154
* the hyperbolic functions :func:`python3:math.cosh`,
155155
:func:`python3:math.sinh` and :func:`python3:math.tanh`
156-
* and the constants :data:`python3:math.e` and :data:`python3:math.pi`.
156+
* and the variables :data:`python3:math.e` and :data:`python3:math.pi`.
157157

158158
Rounding half to even
159159
---------------------

docs/types/sequences-sets/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Sequences (:doc:`lists` and :doc:`tuples`) and sets (:ref:`set` and
55
:ref:`frozenset`) essentially differ in the following properties:
66

77
+---------------+---------------+---------------+---------------+---------------+
8-
| Data type | mutable | ordered | indexed | duplicates |
8+
| Data type | :term:`mutable| ordered | indexed | duplicates |
9+
| | <immutable>` | | | |
910
+===============+===============+===============+===============+===============+
1011
| List |||||
1112
+---------------+---------------+---------------+---------------+---------------+

0 commit comments

Comments
 (0)