Skip to content

Commit 7f7c565

Browse files
committed
✏️ Minor improvements
* Typos * Wording * Reformat pyproject.toml files * Rearrange checks * Measure times for cache decorator
1 parent a0e7922 commit 7f7c565

File tree

16 files changed

+163
-115
lines changed

16 files changed

+163
-115
lines changed

docs/appendix/checks.rst

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ Checks
272272

273273
.. code-block:: pycon
274274
275-
>>> sheet = {}
276-
>>> sheet[("A", 0)] = 1
277-
>>> sheet[("A", 1)] = 2
278-
>>> sheet[("B", 0)] = 3
279-
>>> sheet[("B", 1)] = 4
280-
>>> print(sheet[("A", 1)])
275+
>>> tabular = {}
276+
>>> tabular[("A", 0)] = 1
277+
>>> tabular[("A", 1)] = 2
278+
>>> tabular[("B", 0)] = 3
279+
>>> tabular[("B", 1)] = 4
280+
>>> print(tabular[("A", 1)])
281281
2
282282
283283
* How can you remove all duplicates from a list without changing the order of the
@@ -501,7 +501,7 @@ Checks
501501
>>> pos
502502
[0, 1, 2, 3]
503503
504-
* How would you count the total number of negative numbers in the list ``[-[1,
504+
* How would you count the total number of negative numbers in the list ``[[-1,
505505
0, 1], [-1, 1, 3], [-2, 0, 2]]``?
506506

507507
.. code-block:: pycon
@@ -621,15 +621,11 @@ Checks
621621

622622
.. code-block:: pycon
623623
624-
>> def my_func(*params):
625-
... for i in reversed(params):
626-
... print(i)
627-
...
628-
>>> my_func(1, 2, 3, 4)
629-
4
630-
3
631-
2
632-
1
624+
>>> values = input("Values separated by commas: ")
625+
Values separated by commas: 1,3,2,4
626+
>>> value_list = values.split(",")
627+
>>> reverse(value_list)
628+
['4', '3', '2', '1']
633629
634630
:doc:`/functions/variables`
635631
---------------------------

docs/control-flow/boolean.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ considered ``True``.
3131
4.2
3232
>>> v
3333
4.199999999999999
34+
>>> round(u, 2) == round(v, 2)
35+
True
3436
3537
``is``, ``is not``, ``in``, ``not in``
3638
checks the identity:

docs/control-flow/loops.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Checks
160160

161161
* Which list comprehension would you use to achieve the same result?
162162

163-
* How would you count the total number of negative numbers in the list ``[-[1,
163+
* How would you count the total number of negative numbers in the list ``[[-1,
164164
0, 1], [-1, 1, 3], [-2, 0, 2]]``?
165165

166166
* Creates a generator that only returns odd numbers from 1 to 10.

docs/explore.rst

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,41 @@ Exploring Python
44
Whether you use :ref:`idle` or the :ref:`interactive_shell`, there are some
55
useful functions to explore Python.
66

7+
.. code-block:: pycon
8+
9+
>>> x = 4.2
10+
11+
``type()``
12+
----------
13+
14+
With :py:func:`type`, you can display the object type, for example:
15+
16+
.. code-block:: pycon
17+
18+
>>> type(x)
19+
<class 'float'>
20+
721
.. _help:
822

923
``help()``
1024
----------
1125

12-
``help()`` has two different modes. When you type ``help()``, you call the help
13-
system, which you can use to get information about modules, keywords, and other
14-
topics. When you are in the help system, you will see a prompt with ``help>``.
15-
You can now enter a module name, for example ``float``, to search the `Python
16-
documentation <https://docs.python.org/>`_ for that type.
26+
:py:func:`help` has two different modes. When you type :func:`help`, you call
27+
the help system, which you can use to get information about modules, keywords,
28+
and other topics. When you are in the help system, you will see a prompt with
29+
``help>``. You can now enter a module name, for example ``float``, to search the
30+
`Python documentation <https://docs.python.org/>`_ for that type.
1731

18-
``help()`` is part of the :doc:`pydoc <python3:library/pydoc>` library, which
32+
:func:`help` is part of the :doc:`pydoc <python3:library/pydoc>` library, which
1933
provides access to the documentation built into Python libraries. Since every
2034
Python installation comes with full documentation, you have all the
2135
documentation at your fingertips even offline.
2236

23-
Alternatively, you can use ``help()`` more specifically by passing a type or
37+
Alternatively, you can use :func:`help` more specifically by passing a type or
2438
variable name as a parameter, for example:
2539

2640
.. code-block:: pycon
2741
28-
>>> x = 4.2
2942
>>> help(x)
3043
Help on float object:
3144
@@ -39,14 +52,27 @@ variable name as a parameter, for example:
3952
| __abs__(self, /)
4053
| abs(self)
4154
...
55+
| is_integer(self, /)
56+
| Return True if the float is an integer.
57+
...
4258
4359
For example, you will learn that ``x`` is of type ``float`` and has a function
44-
:func:`__add__` that you can use with dot notation:
60+
:func:`is_integer` that you can use with dot notation:
61+
62+
.. code-block:: pycon
63+
64+
>>> x.is_integer()
65+
False
66+
67+
``id()``
68+
--------
69+
70+
:py:func:`id` specifies the identification number of an object, for example:
4571

4672
.. code-block:: pycon
4773
48-
>>> x.__add__(1)
49-
5.2
74+
>>> id(x)
75+
4304262800
5076
5177
``dir()``
5278
---------

docs/functions/decorators.rst

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,25 @@ as decorators, such as:
7878
.. code-block:: pycon
7979
:linenos:
8080
81-
>>> from functools import cache
82-
>>> @cache
81+
>>> import timeit
82+
... from functools import cache
83+
... @cache
8384
... def factorial(n):
8485
... return n * factorial(n - 1) if n else 1
85-
...
86-
>>> factorial(8)
87-
40320
88-
>>> factorial(10)
89-
3628800
90-
91-
Line 6
92-
Since there is no previously stored result, nine recursive calls are
93-
made.
94-
Line 8
95-
makes only two new calls, as the other results come from the cache.
86+
... timeit.timeit("factorial(8)", globals=globals())
87+
0.02631620899774134
88+
89+
Line 1
90+
imports the :mod:`timeit` module for measuring execution time.
91+
Line 2
92+
imports :func:`functools.cache`.
93+
Line 5
94+
The ``@cache`` decorator is used to store intermediate results, which
95+
can then be reused. In our case, the execution speed is increased
96+
approximately tenfold.
97+
Line 10
98+
:func:`timeit.timeit` measures the time of a call. Unless otherwise
99+
specified, the call is made one million times.
96100

97101
:func:`functools.wraps`
98102
This decorator makes the wrapper function look like the original function

docs/functions/params.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Python offers flexible mechanisms for passing :term:`arguments <argument>` to
2424
...
2525
>>> func2(5, w=6)
2626
45
27-
>>> def func3(u, v=1, w=1, *tup):
28-
... print((u, v, w) + tup)
27+
>>> def func3(u, v=1, w=1, *args):
28+
... print((u, v, w) + args)
2929
...
3030
>>> func3(7)
3131
(7, 1, 1)

docs/packs/dataprep/pyproject.toml

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,50 @@
11
[build-system]
2-
requires = ["Cython", "setuptools>=77.0"]
32
build-backend = "setuptools.build_meta"
3+
requires = [ "cython", "setuptools>=77" ]
44

55
[project]
66
name = "dataprep"
77
version = "0.1.0"
8-
authors = [
9-
{ name="Veit Schiele", email="[email protected]" },
10-
]
118
description = "A small dataprep package"
129
readme = "README.rst"
13-
License-Expression = "BSD-3-Clause"
14-
License-File = [ "LICENSE" ]
10+
authors = [
11+
{ name = "Veit Schiele", email = "[email protected]" },
12+
]
1513
requires-python = ">=3.9"
1614
classifiers = [
17-
"Programming Language :: Python :: 3",
18-
"License :: OSI Approved :: BSD License",
19-
"Operating System :: OS Independent",
15+
"License :: OSI Approved :: BSD License",
16+
"Operating System :: OS Independent",
17+
"Programming Language :: Python :: 3 :: Only",
18+
"Programming Language :: Python :: 3.9",
19+
"Programming Language :: Python :: 3.10",
20+
"Programming Language :: Python :: 3.11",
21+
"Programming Language :: Python :: 3.12",
22+
"Programming Language :: Python :: 3.13",
23+
"Programming Language :: Python :: 3.14",
2024
]
2125
dependencies = [
22-
"Cython",
23-
"pandas",
26+
"cython",
27+
"pandas",
2428
]
2529

30+
urls."Bug Tracker" = "https://github.com/veit/dataprep/issues"
31+
urls."Homepage" = "https://github.com/veit/dataprep"
32+
License-Expression = "BSD-3-Clause"
33+
License-File = [ "LICENSE" ]
34+
2635
[dependency-groups]
27-
tests = [
28-
"coverage[toml]",
29-
"pytest>=6.0",
36+
dev = [
37+
"pre-commit",
38+
{ include-group = "docs" },
39+
{ include-group = "tests" },
3040
]
3141
docs = [
32-
"furo",
33-
"sphinxext-opengraph",
34-
"sphinx-copybutton",
35-
"sphinx_inline_tabs"
42+
"furo",
43+
"sphinx-copybutton",
44+
"sphinx-inline-tabs",
45+
"sphinxext-opengraph",
3646
]
37-
dev = [
38-
{include-group = "tests"},
39-
{include-group = "docs"},
40-
"pre-commit",
47+
tests = [
48+
"coverage[toml]",
49+
"pytest>=6",
4150
]
42-
43-
[project.urls]
44-
"Homepage" = "https://github.com/veit/dataprep"
45-
"Bug Tracker" = "https://github.com/veit/dataprep/issues"

docs/packs/distribution.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ as:
238238

239239
.. _license-expression:
240240

241-
``License-Expression``
241+
``license-expression``
242242
contains valid `SPDX license expressions
243243
<https://spdx.github.io/spdx-spec/v2.2.2/SPDX-license-expressions/>`_.
244244

docs/packs/myapp/pyproject.toml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
[build-system]
2+
build-backend = "hatchling.build"
3+
requires = [ "hatchling" ]
4+
15
[project]
26
name = "myapp"
37
version = "0.1.0"
48
description = "Add your description here"
59
readme = "README.md"
610
authors = [
7-
{ name = "Veit Schiele", email = "[email protected]" }
11+
{ name = "Veit Schiele", email = "[email protected]" },
812
]
913
requires-python = ">=3.13"
10-
dependencies = []
11-
12-
[project.scripts]
13-
myapp = "myapp:main"
14+
classifiers = [
15+
"Programming Language :: Python :: 3 :: Only",
16+
"Programming Language :: Python :: 3.13",
17+
"Programming Language :: Python :: 3.14",
18+
]
19+
dependencies = [ ]
1420

15-
[build-system]
16-
requires = ["hatchling"]
17-
build-backend = "hatchling.build"
21+
scripts.myapp = "myapp:main"

docs/packs/mypack/pyproject.toml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
[build-system]
2+
build-backend = "hatchling.build"
3+
requires = [ "hatchling" ]
4+
15
[project]
26
name = "mypack"
37
version = "0.1.0"
48
description = "Add your description here"
59
readme = "README.md"
610
authors = [
7-
{ name = "Veit Schiele", email = "[email protected]" }
11+
{ name = "Veit Schiele", email = "[email protected]" },
812
]
913
requires-python = ">=3.13"
10-
dependencies = []
11-
12-
[project.scripts]
13-
mypack = "mypack:main"
14+
classifiers = [
15+
"Programming Language :: Python :: 3 :: Only",
16+
"Programming Language :: Python :: 3.13",
17+
"Programming Language :: Python :: 3.14",
18+
]
19+
dependencies = [ ]
1420

15-
[build-system]
16-
requires = ["hatchling"]
17-
build-backend = "hatchling.build"
21+
scripts.mypack = "mypack:main"

0 commit comments

Comments
 (0)