Compare commits
10 Commits
82b4fe2163
...
28d6d03315
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28d6d03315 | ||
|
|
2e84544aff | ||
|
|
434f8d26b6 | ||
|
|
8158222f22 | ||
|
|
a40bd03b0e | ||
|
|
536e68686f | ||
|
|
5f2c3abfc7 | ||
|
|
b39c1c1f04 | ||
|
|
08318a657a | ||
|
|
646427f393 |
File diff suppressed because it is too large
Load Diff
22
08-def-type-hints/callable/variance.py
Normal file
22
08-def-type-hints/callable/variance.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
def update( # <1>
|
||||||
|
probe: Callable[[], float], # <2>
|
||||||
|
display: Callable[[float], None] # <3>
|
||||||
|
) -> None:
|
||||||
|
temperature = probe()
|
||||||
|
# imagine lots of control code here
|
||||||
|
display(temperature)
|
||||||
|
|
||||||
|
def probe_ok() -> int: # <4>
|
||||||
|
return 42
|
||||||
|
|
||||||
|
def display_wrong(temperature: int) -> None: # <5>
|
||||||
|
print(hex(temperature))
|
||||||
|
|
||||||
|
update(probe_ok, display_wrong) # type error # <6>
|
||||||
|
|
||||||
|
def display_ok(temperature: complex) -> None: # <7>
|
||||||
|
print(temperature)
|
||||||
|
|
||||||
|
update(probe_ok, display_ok) # OK # <8>
|
||||||
35
README.md
35
README.md
@@ -1,14 +1,7 @@
|
|||||||
# Fluent Python 2e example code
|
# Fluent Python 2e example code
|
||||||
|
|
||||||
Example code for the book **Fluent Python, 2<sup>nd</sup> edition** by Luciano Ramalho (O'Reilly, 2021).
|
Example code for the book **Fluent Python, Second Edition** by Luciano Ramalho (O'Reilly, 2022).
|
||||||
|
|
||||||
> **BEWARE**: This is a work in progress!
|
|
||||||
>
|
|
||||||
> * Code here may change and disappear without warning.
|
|
||||||
>
|
|
||||||
> * Major reorganizations may happen at any time.
|
|
||||||
>
|
|
||||||
> * No promises. No guarantees. Use at own risk.
|
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
@@ -16,37 +9,37 @@ All chapters are undergoing review and updates, including significant rewrites i
|
|||||||
|
|
||||||
New chapters in **Fluent Python 2e** are marked with 🆕.
|
New chapters in **Fluent Python 2e** are marked with 🆕.
|
||||||
|
|
||||||
🚨 This table of contents is subject to change at any time until the book goes to the printer.
|
> 🚨 This table of contents is subject to change at any time until the book goes to the printer.<BR>
|
||||||
|
Latest change: Old **Part I—Prologue** merged into new **Part I—Data Structures**; parts renumbered accordingly; chapter numbers unchanged.
|
||||||
|
|
||||||
Part / Chapter #|Title|Directory|1<sup>st</sup> ed. Chapter #
|
Part / Chapter #|Title|Directory|1<sup>st</sup> ed. Chapter #
|
||||||
---:|---|---|:---:
|
---:|---|---|:---:
|
||||||
**I – Prologue**|
|
**I – Data Structures**|
|
||||||
1|The Python Data Model|[01-data-model](01-data-model)|1
|
1|The Python Data Model|[01-data-model](01-data-model)|1
|
||||||
**II – Data Structures**|
|
|
||||||
2|An Array of Sequences|[02-array-seq](02-array-seq)|2
|
2|An Array of Sequences|[02-array-seq](02-array-seq)|2
|
||||||
3|Dictionaries and Sets|[03-dict-set](03-dict-set)|3
|
3|Dictionaries and Sets|[03-dict-set](03-dict-set)|3
|
||||||
4|Unicode Text versus Bytes|[04-text-byte](04-text-byte)|4
|
4|Unicode Text versus Bytes|[04-text-byte](04-text-byte)|4
|
||||||
5|Data Class Builders|[05-data-classes](05-data-classes)|🆕
|
5|Data Class Builders|[05-data-classes](05-data-classes)|🆕
|
||||||
6|Object References, Mutability, and Recycling|[06-obj-ref](06-obj-ref)|8
|
6|Object References, Mutability, and Recycling|[06-obj-ref](06-obj-ref)|8
|
||||||
**III – Functions as Objects**|
|
**II – Functions as Objects**|
|
||||||
7|Funcions as First-Class Objects|[07-1class-func](07-1class-func)|5
|
7|Funcions as First-Class Objects|[07-1class-func](07-1class-func)|5
|
||||||
8|Type Hints in Function Definitions|[08-def-type-hints](08-def-type-hints)|🆕
|
8|Type Hints in Functions|[08-def-type-hints](08-def-type-hints)|🆕
|
||||||
9|Function Decorators and Closures|[09-closure-deco](09-closure-deco)|7
|
9|Decorators and Closures|[09-closure-deco](09-closure-deco)|7
|
||||||
10|Design Patterns with First-Class Functions|[10-dp-1class-func](10-dp-1class-func)|6
|
10|Design Patterns with First-Class Functions|[10-dp-1class-func](10-dp-1class-func)|6
|
||||||
**IV – Object-Oriented Idioms**|
|
**III – Object-Oriented Idioms**|
|
||||||
11|A Pythonic Object|[11-pythonic-obj](11-pythonic-obj)|9
|
11|A Pythonic Object|[11-pythonic-obj](11-pythonic-obj)|9
|
||||||
12|Sequence Hacking, Hashing, and Slicing|[12-seq-hacking](12-seq-hacking)|10
|
12|Special Methods for Sequences|[12-seq-hacking](12-seq-hacking)|10
|
||||||
13|Interfaces, Protocols, and ABCs|[13-protocl-abc](13-protocol-abc)|11
|
13|Interfaces, Protocols, and ABCs|[13-protocl-abc](13-protocol-abc)|11
|
||||||
14|Inheritance: For Good or For Worse|[14-inheritance](14-inheritance)|12
|
14|Inheritance: For Better or For Worse|[14-inheritance](14-inheritance)|12
|
||||||
15|More About Type Hints|[15-more-types](15-more-types)|🆕
|
15|More About Type Hints|[15-more-types](15-more-types)|🆕
|
||||||
16|Operator Overloading: Doing It Right|[16-op-overloading](16-op-overloading)|13
|
16|Operator Overloading|[16-op-overloading](16-op-overloading)|13
|
||||||
**V – Control Flow**|
|
**IV – Control Flow**|
|
||||||
17|Iterators, Generators, and Classic Coroutines|[17-it-generator](17-it-generator)|14
|
17|Iterators, Generators, and Classic Coroutines|[17-it-generator](17-it-generator)|14
|
||||||
18|Context Managers and else Blocks|[18-with-match](18-with-match)|15
|
18|with, match, and else Blocks|[18-with-match](18-with-match)|15
|
||||||
19|Concurrency Models in Python|[19-concurrency](19-concurrency)|🆕
|
19|Concurrency Models in Python|[19-concurrency](19-concurrency)|🆕
|
||||||
20|Concurrent Executors|[20-executors](20-executors)|17
|
20|Concurrent Executors|[20-executors](20-executors)|17
|
||||||
21|Asynchronous Programming|[21-async](21-async)|18
|
21|Asynchronous Programming|[21-async](21-async)|18
|
||||||
**VI – Metaprogramming**|
|
**V – Metaprogramming**|
|
||||||
22|Dynamic Attributes and Properties|[22-dyn-attr-prop](22-dyn-attr-prop)|19
|
22|Dynamic Attributes and Properties|[22-dyn-attr-prop](22-dyn-attr-prop)|19
|
||||||
23|Attribute Descriptors|[23-descriptor](23-descriptor)|20
|
23|Attribute Descriptors|[23-descriptor](23-descriptor)|20
|
||||||
24|Class Metaprogramming|[24-class-metaprog](24-class-metaprog)|21
|
24|Class Metaprogramming|[24-class-metaprog](24-class-metaprog)|21
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,10 @@ I replaced almost all URLs in the book with shortened versions that go through t
|
|||||||
The site has an `.htaccess` file with *temporary* redirects.
|
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,
|
When I find out a link is stale, I can thange the redirect in `.htaccess` to a new target,
|
||||||
so the link in the book is back in service through the updated redirect.
|
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
|
## Help wanted
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
ErrorDocument 404 /404.html
|
ErrorDocument 404 /404.html
|
||||||
|
|
||||||
# main resources
|
# main resources
|
||||||
|
RedirectTemp /book https://www.oreilly.com/library/view/fluent-python-2nd/9781492056348/
|
||||||
RedirectTemp /code https://github.com/fluentpython/example-code-2e
|
RedirectTemp /code https://github.com/fluentpython/example-code-2e
|
||||||
RedirectTemp /home https://www.fluentpython.com/
|
RedirectTemp /home https://www.fluentpython.com/
|
||||||
|
|
||||||
# URLs mentioned at least three times
|
# URLs mentioned at least three times
|
||||||
RedirectTemp /bisect https://www.fluentpython.com/extra/ordered-sequences-with-bisect/
|
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 /cardxvi https://www.python.org/dev/peps/pep-0484/#the-numeric-tower
|
||||||
RedirectTemp /collec https://docs.python.org/3/library/collections.html
|
RedirectTemp /collec https://docs.python.org/3/library/collections.html
|
||||||
RedirectTemp /dask https://dask.org/
|
RedirectTemp /dask https://dask.org/
|
||||||
RedirectTemp /dtmodel https://docs.python.org/3/reference/datamodel.html
|
RedirectTemp /dtmodel https://docs.python.org/3/reference/datamodel.html
|
||||||
RedirectTemp /descr101 https://www.python.org/download/releases/2.2.3/descrintro/
|
RedirectTemp /descr101 https://www.python.org/download/releases/2.2.3/descrintro/
|
||||||
RedirectTemp /descrhow https://docs.python.org/3/howto/descriptor.html
|
RedirectTemp /descrhow https://docs.python.org/3/howto/descriptor.html
|
||||||
RedirectTemp /doctest https://docs.python.org/3/library/doctest.html
|
RedirectTemp /doctest https://docs.python.org/3/library/doctest.html
|
||||||
RedirectTemp /effectpy https://effectivepython.com/
|
RedirectTemp /effectpy https://effectivepython.com/
|
||||||
RedirectTemp /fmtspec https://docs.python.org/3/library/string.html#formatspec
|
RedirectTemp /fmtspec https://docs.python.org/3/library/string.html#formatspec
|
||||||
RedirectTemp /gunicorn https://gunicorn.org/
|
RedirectTemp /gunicorn https://gunicorn.org/
|
||||||
RedirectTemp /hashint https://www.fluentpython.com/extra/internals-of-sets-and-dicts/
|
RedirectTemp /hashint https://www.fluentpython.com/extra/internals-of-sets-and-dicts/
|
||||||
@@ -25,6 +26,19 @@ RedirectTemp /norvigdp http://norvig.com/design-patterns/
|
|||||||
RedirectTemp /nsphere https://en.wikipedia.org/wiki/N-sphere
|
RedirectTemp /nsphere https://en.wikipedia.org/wiki/N-sphere
|
||||||
RedirectTemp /oldcoro https://www.fluentpython.com/extra/classic-coroutines/
|
RedirectTemp /oldcoro https://www.fluentpython.com/extra/classic-coroutines/
|
||||||
RedirectTemp /pandas https://pandas.pydata.org/
|
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 /pep218 https://www.python.org/dev/peps/pep-0218/
|
||||||
RedirectTemp /pep227 https://www.python.org/dev/peps/pep-0227/
|
RedirectTemp /pep227 https://www.python.org/dev/peps/pep-0227/
|
||||||
RedirectTemp /pep255 https://www.python.org/dev/peps/pep-0255/
|
RedirectTemp /pep255 https://www.python.org/dev/peps/pep-0255/
|
||||||
@@ -100,10 +114,3 @@ RedirectTemp /pep3141 https://www.python.org/dev/peps/pep-3141/
|
|||||||
RedirectTemp /pep3148 https://www.python.org/dev/peps/pep-3148/
|
RedirectTemp /pep3148 https://www.python.org/dev/peps/pep-3148/
|
||||||
RedirectTemp /pep3155 https://www.python.org/dev/peps/pep-3155/
|
RedirectTemp /pep3155 https://www.python.org/dev/peps/pep-3155/
|
||||||
RedirectTemp /pep3333 https://www.python.org/dev/peps/pep-3333/
|
RedirectTemp /pep3333 https://www.python.org/dev/peps/pep-3333/
|
||||||
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 /slatkin https://effectivepython.com/
|
|
||||||
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/
|
|
||||||
|
|||||||
2
links/deploy.sh
Executable file
2
links/deploy.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
scp FPY.LI.htaccess dh_i4p2ka@fpy.li:~/fpy.li/.htaccess
|
||||||
Reference in New Issue
Block a user