diff --git a/01-data-model/data-model.ipynb b/01-data-model/data-model.ipynb index f525899..5b30397 100644 --- a/01-data-model/data-model.ipynb +++ b/01-data-model/data-model.ipynb @@ -482,7 +482,7 @@ " self.y = y\n", "\n", " def __repr__(self):\n", - " return 'Vector(%r, %r)' % (self.x, self.y)\n", + " return f'Vector({self.x!r}, {self.y!r})'\n", "\n", " def __abs__(self):\n", " return math.hypot(self.x, self.y)\n", diff --git a/02-array-seq/test.sh b/02-array-seq/test.sh index 4747320..906717d 100755 --- a/02-array-seq/test.sh +++ b/02-array-seq/test.sh @@ -1,4 +1,4 @@ #!/bin/bash python3 -m doctest bisect_demo.py -python3 -m doctest metro_lat_long.py +python3 -m doctest metro_lat_lon.py pytest -q --nbval diff --git a/06-obj-ref/README.rst b/06-obj-ref/README.rst index deac2fa..0d705e6 100644 --- a/06-obj-ref/README.rst +++ b/06-obj-ref/README.rst @@ -1,4 +1,4 @@ -Sample code for Chapter 8 - "Object references, mutability and recycling" +Sample code for Chapter 6 - "Object references, mutability and recycling" From the book "Fluent Python" by Luciano Ramalho (O'Reilly, 2015) http://shop.oreilly.com/product/0636920032519.do diff --git a/08-def-type-hints/coordinates/requirements.txt b/08-def-type-hints/coordinates/requirements.txt index fb11094..7b7b424 100644 --- a/08-def-type-hints/coordinates/requirements.txt +++ b/08-def-type-hints/coordinates/requirements.txt @@ -1,2 +1,2 @@ geolib==1.0.7 -future==0.18.2 +future==0.18.3 diff --git a/17-it-generator/columnize_iter.py b/17-it-generator/columnize_iter.py index cee0f13..4362bc1 100644 --- a/17-it-generator/columnize_iter.py +++ b/17-it-generator/columnize_iter.py @@ -6,8 +6,8 @@ def columnize( ) -> Iterator[tuple[str, ...]]: # <1> if num_columns == 0: num_columns = round(len(sequence) ** 0.5) - num_rows, reminder = divmod(len(sequence), num_columns) - num_rows += bool(reminder) + num_rows, remainder = divmod(len(sequence), num_columns) + num_rows += bool(remainder) return (tuple(sequence[i::num_rows]) for i in range(num_rows)) # <2> # end::COLUMNIZE[] diff --git a/20-executors/getflags/flags2_asyncio.py b/20-executors/getflags/flags2_asyncio.py index 4f1849a..b697840 100755 --- a/20-executors/getflags/flags2_asyncio.py +++ b/20-executors/getflags/flags2_asyncio.py @@ -79,6 +79,8 @@ async def supervisor(cc_list: list[str], error = exc # <10> except KeyboardInterrupt: break + else: + error = None if error: status = DownloadStatus.ERROR # <11> diff --git a/20-executors/getflags/requirements.txt b/20-executors/getflags/requirements.txt index b8bb630..9b1faeb 100644 --- a/20-executors/getflags/requirements.txt +++ b/20-executors/getflags/requirements.txt @@ -1,10 +1,10 @@ anyio==3.3.2 -certifi==2021.5.30 +certifi==2024.7.4 charset-normalizer==2.0.6 -h11==0.12.0 +h11==0.16.0 httpcore==0.13.7 httpx==1.0.0b0 -idna==3.2 +idna==3.7 rfc3986==1.5.0 sniffio==1.2.0 -tqdm==4.62.3 +tqdm==4.66.3 diff --git a/21-async/mojifinder/requirements.txt b/21-async/mojifinder/requirements.txt index 1f7c3d6..6831fee 100644 --- a/21-async/mojifinder/requirements.txt +++ b/21-async/mojifinder/requirements.txt @@ -1,7 +1,7 @@ click==7.1.2 fastapi==0.65.2 -h11==0.12.0 -pydantic==1.8.2 -starlette==0.13.6 +h11==0.16.0 +pydantic==1.10.13 +starlette==0.40.0 typing-extensions==3.7.4.3 uvicorn==0.13.4 diff --git a/links/FPY.LI.htaccess b/links/FPY.LI.htaccess index cc779db..5607fa4 100644 --- a/links/FPY.LI.htaccess +++ b/links/FPY.LI.htaccess @@ -1,3 +1,6 @@ +# to recreate or update this file: +# $ cat custom.htaccess short.htaccess > FPY.LI.htaccess + ErrorDocument 404 /404.html # main resources @@ -1070,3 +1073,17 @@ RedirectTemp /24-27 https://docs.python.org/3/library/functools.html#functools.t RedirectTemp /24-28 https://www.python.org/download/releases/2.2.3/descrintro/ RedirectTemp /24-29 https://github.com/lihaoyi/macropy RedirectTemp /24-30 https://people.eecs.berkeley.edu/~bh/ss-toc2.html +# content of short.htaccess file created and managed by short.py + +# appended: 2025-05-23 15:12:13 +RedirectTemp /22 https://pythonfluente.com/2/#pattern_matching_case_study_sec +RedirectTemp /23 https://pythonfluente.com/2/#how_slicing_works +RedirectTemp /24 https://pythonfluente.com/2/#sliceable_sequence +RedirectTemp /25 https://pythonfluente.com/2/#virtual_subclass_sec +RedirectTemp /26 https://pythonfluente.com/2/#environment_class_ex +RedirectTemp /27 https://pythonfluente.com/2/#subclass_builtin_woes +RedirectTemp /28 https://pythonfluente.com/2/#slots_section +RedirectTemp /29 https://pythonfluente.com/2/#typeddict_sec +RedirectTemp /2a https://pythonfluente.com/2/#problems_annot_runtime_sec +RedirectTemp /2b https://pythonfluente.com/2/#legacy_deprecated_typing_box +RedirectTemp /2c https://pythonfluente.com/2/#positional_pattern_implement_sec diff --git a/links/README.md b/links/README.md index 6da595c..65749b2 100644 --- a/links/README.md +++ b/links/README.md @@ -1,40 +1,6 @@ -# Short links for URLs in the book +This file is deployed as `.htaccess` to the FPY.LI domain +to map short URLs in Fluent Python to the original URLs. -## Problem: link rot +To update it, I use tools in this other repo: -_Fluent Python, Second Edition_ has more than 1000 links to external resources. -Inevitably, some of those links will rot as time passes. -But I can't change the URLs in the print book... - -## Solution: indirection - -I replaced almost all URLs in the book with shortened versions that go through the `fpy.li` site which I control. -The site has an `.htaccess` file with *temporary* redirects. - -When I find out a link is stale, I can thange the redirect in `.htaccess` to a new target, -which may be a link to copy in the Internet Archive's -[Wayback Machine](https://archive.org/web/) -o the link in the book is back in service through the updated redirect. - - -## Help wanted - -Please report broken links as bugs in the [`FPY.LI.htaccess`](FPY.LI.htaccess) file. -Also, feel free to send pull requests with fixes to that file. -When I accept a PR, I will redeploy it to `fpy.li/.htaccess`. - -## Details - -Almost all URLs in the book are replaced with shortened versions like -[`http://fpy.li/1-3`](http://fpy.li/1-3)—for chapter 1, link #3. - -There are also custom short URLs like -[`https://fpy.li/code`](https://fpy.li/code) which redirects to the example code repository. -I used custom short URLs for URLs with 3 or more mentions, or links to PEPs. - -Exceptions: - -- URLs with `oreilly` in them are unchanged; -- `fluentpython.com` URL (with no path) is unchanged; - -The `FPY.LI.htaccess` is deployed at the root folder in `http://fpy.li`. +https://github.com/pythonfluente/pythonfluente2e diff --git a/links/custom.htaccess b/links/custom.htaccess deleted file mode 100644 index ad10802..0000000 --- a/links/custom.htaccess +++ /dev/null @@ -1,116 +0,0 @@ -ErrorDocument 404 /404.html - -# main resources -RedirectTemp /book https://www.oreilly.com/library/view/fluent-python-2nd/9781492056348/ -RedirectTemp /code https://github.com/fluentpython/example-code-2e -RedirectTemp /home https://www.fluentpython.com/ - -# URLs mentioned at least three times -RedirectTemp /bisect https://www.fluentpython.com/extra/ordered-sequences-with-bisect/ -RedirectTemp /cardxvi https://www.python.org/dev/peps/pep-0484/#the-numeric-tower -RedirectTemp /collec https://docs.python.org/3/library/collections.html -RedirectTemp /dask https://dask.org/ -RedirectTemp /dtmodel https://docs.python.org/3/reference/datamodel.html -RedirectTemp /descr101 https://www.python.org/download/releases/2.2.3/descrintro/ -RedirectTemp /descrhow https://docs.python.org/3/howto/descriptor.html -RedirectTemp /doctest https://docs.python.org/3/library/doctest.html -RedirectTemp /effectpy https://effectivepython.com/ -RedirectTemp /fmtspec https://docs.python.org/3/library/string.html#formatspec -RedirectTemp /gunicorn https://gunicorn.org/ -RedirectTemp /hashint https://www.fluentpython.com/extra/internals-of-sets-and-dicts/ -RedirectTemp /hattingh https://www.oreilly.com/library/view/using-asyncio-in/9781492075325/ -RedirectTemp /httpx https://www.python-httpx.org/ -RedirectTemp /initvar https://docs.python.org/3/library/dataclasses.html#init-only-variables -RedirectTemp /mypy https://mypy.readthedocs.io/en/stable/ -RedirectTemp /norvigdp http://norvig.com/design-patterns/ -RedirectTemp /nsphere https://en.wikipedia.org/wiki/N-sphere -RedirectTemp /oldcoro https://www.fluentpython.com/extra/classic-coroutines/ -RedirectTemp /pandas https://pandas.pydata.org/ -RedirectTemp /pycook3 https://www.oreilly.com/library/view/python-cookbook-3rd/9781449357337/ -RedirectTemp /pynut3 https://www.oreilly.com/library/view/python-in-a/9781491913833/ -RedirectTemp /pypydif https://doc.pypy.org/en/latest/cpython_differences.html#subclasses-of-built-in-types -RedirectTemp /shed4051 https://github.com/python/typeshed/issues/4051 -RedirectTemp /specattr https://docs.python.org/3/library/stdtypes.html#special-attributes -RedirectTemp /typecoro https://docs.python.org/3.10/library/typing.html#typing.Coroutine -RedirectTemp /typing https://docs.python.org/3/library/typing.html -RedirectTemp /weakref https://www.fluentpython.com/extra/weak-references/ - -# URL added during QA of the Second Edition -RedirectTemp /bdfl https://www.artima.com/weblogs/viewpost.jsp?thread=235725 - -# Python Enhancement Proposals -RedirectTemp /pep218 https://www.python.org/dev/peps/pep-0218/ -RedirectTemp /pep227 https://www.python.org/dev/peps/pep-0227/ -RedirectTemp /pep255 https://www.python.org/dev/peps/pep-0255/ -RedirectTemp /pep342 https://www.python.org/dev/peps/pep-0342/ -RedirectTemp /pep343 https://www.python.org/dev/peps/pep-0343/ -RedirectTemp /pep357 https://www.python.org/dev/peps/pep-0357/ -RedirectTemp /pep362 https://www.python.org/dev/peps/pep-0362/ -RedirectTemp /pep371 https://www.python.org/dev/peps/pep-0371/ -RedirectTemp /pep380 https://www.python.org/dev/peps/pep-0380/ -RedirectTemp /pep393 https://www.python.org/dev/peps/pep-0393/ -RedirectTemp /pep412 https://www.python.org/dev/peps/pep-0412/ -RedirectTemp /pep442 https://www.python.org/dev/peps/pep-0442/ -RedirectTemp /pep443 https://www.python.org/dev/peps/pep-0443/ -RedirectTemp /pep448 https://www.python.org/dev/peps/pep-0448/ -RedirectTemp /pep455 https://www.python.org/dev/peps/pep-0455/ -RedirectTemp /pep456 https://www.python.org/dev/peps/pep-0456/ -RedirectTemp /pep461 https://www.python.org/dev/peps/pep-0461/ -RedirectTemp /pep465 https://www.python.org/dev/peps/pep-0465/ -RedirectTemp /pep467 https://www.python.org/dev/peps/pep-0467/ -RedirectTemp /pep482 https://www.python.org/dev/peps/pep-0482/ -RedirectTemp /pep483 https://www.python.org/dev/peps/pep-0483/ -RedirectTemp /pep484 https://www.python.org/dev/peps/pep-0484/ -RedirectTemp /pep487 https://www.python.org/dev/peps/pep-0487/ -RedirectTemp /pep492 https://www.python.org/dev/peps/pep-0492/ -RedirectTemp /pep519 https://www.python.org/dev/peps/pep-0519/ -RedirectTemp /pep525 https://www.python.org/dev/peps/pep-0525/ -RedirectTemp /pep526 https://www.python.org/dev/peps/pep-0526/ -RedirectTemp /pep528 https://www.python.org/dev/peps/pep-0528/ -RedirectTemp /pep529 https://www.python.org/dev/peps/pep-0529/ -RedirectTemp /pep530 https://www.python.org/dev/peps/pep-0530/ -RedirectTemp /pep544 https://www.python.org/dev/peps/pep-0544/ -RedirectTemp /pep554 https://www.python.org/dev/peps/pep-0554/ -RedirectTemp /pep557 https://www.python.org/dev/peps/pep-0557/ -RedirectTemp /pep560 https://www.python.org/dev/peps/pep-0560/ -RedirectTemp /pep561 https://www.python.org/dev/peps/pep-0561/ -RedirectTemp /pep563 https://www.python.org/dev/peps/pep-0563/ -RedirectTemp /pep570 https://www.python.org/dev/peps/pep-0570/ -RedirectTemp /pep572 https://www.python.org/dev/peps/pep-0572/ -RedirectTemp /pep584 https://www.python.org/dev/peps/pep-0584/ -RedirectTemp /pep585 https://www.python.org/dev/peps/pep-0585/ -RedirectTemp /pep586 https://www.python.org/dev/peps/pep-0586/ -RedirectTemp /pep589 https://www.python.org/dev/peps/pep-0589/ -RedirectTemp /pep591 https://www.python.org/dev/peps/pep-0591/ -RedirectTemp /pep593 https://www.python.org/dev/peps/pep-0593/ -RedirectTemp /pep604 https://www.python.org/dev/peps/pep-0604/ -RedirectTemp /pep612 https://www.python.org/dev/peps/pep-0612/ -RedirectTemp /pep613 https://www.python.org/dev/peps/pep-0613/ -RedirectTemp /pep616 https://www.python.org/dev/peps/pep-0616/ -RedirectTemp /pep617 https://www.python.org/dev/peps/pep-0617/ -RedirectTemp /pep618 https://www.python.org/dev/peps/pep-0618/ -RedirectTemp /pep634 https://www.python.org/dev/peps/pep-0634/ -RedirectTemp /pep635 https://www.python.org/dev/peps/pep-0635/ -RedirectTemp /pep636 https://www.python.org/dev/peps/pep-0636/ -RedirectTemp /pep638 https://www.python.org/dev/peps/pep-0638/ -RedirectTemp /pep645 https://www.python.org/dev/peps/pep-0645/ -RedirectTemp /pep646 https://www.python.org/dev/peps/pep-0646/ -RedirectTemp /pep647 https://www.python.org/dev/peps/pep-0647/ -RedirectTemp /pep649 https://www.python.org/dev/peps/pep-0649/ -RedirectTemp /pep654 https://www.python.org/dev/peps/pep-0654/ -RedirectTemp /pep655 https://www.python.org/dev/peps/pep-0655/ -RedirectTemp /pep661 https://www.python.org/dev/peps/pep-0661/ -RedirectTemp /pep3099 https://www.python.org/dev/peps/pep-3099/ -RedirectTemp /pep3102 https://www.python.org/dev/peps/pep-3102/ -RedirectTemp /pep3104 https://www.python.org/dev/peps/pep-3104/ -RedirectTemp /pep3106 https://www.python.org/dev/peps/pep-3106/ -RedirectTemp /pep3107 https://www.python.org/dev/peps/pep-3107/ -RedirectTemp /pep3115 https://www.python.org/dev/peps/pep-3115/ -RedirectTemp /pep3118 https://www.python.org/dev/peps/pep-3118/ -RedirectTemp /pep3119 https://www.python.org/dev/peps/pep-3119/ -RedirectTemp /pep3129 https://www.python.org/dev/peps/pep-3129/ -RedirectTemp /pep3132 https://www.python.org/dev/peps/pep-3132/ -RedirectTemp /pep3141 https://www.python.org/dev/peps/pep-3141/ -RedirectTemp /pep3148 https://www.python.org/dev/peps/pep-3148/ -RedirectTemp /pep3155 https://www.python.org/dev/peps/pep-3155/ -RedirectTemp /pep3333 https://www.python.org/dev/peps/pep-3333/ diff --git a/links/deploy.sh b/links/deploy.sh deleted file mode 100755 index ced9bd9..0000000 --- a/links/deploy.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -scp FPY.LI.htaccess dh_i4p2ka@fpy.li:~/fpy.li/.htaccess diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..f7b07e2 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,4 @@ +line-length = 100 +[format] +# Like Python's repr(), use single quotes for strings. +quote-style = "single" \ No newline at end of file