example-code-2e icon indicating copy to clipboard operation
example-code-2e copied to clipboard

Example code for Fluent Python, 2nd edition (O'Reilly 2022)

Results 35 example-code-2e issues
Sort by recently updated
recently updated
newest added

Consider the example in 24-class-metaprog/factories.py (corresponds to example 24-2, page 912 in my copy) ``` Dog = record_factory('Dog', 'name weight owner') rex = Dog('Rex', 30, 'Bob') ``` We do not...

hi. so i know that you probably know this but if there will be a 3rd edition, exapmles 19-13 and 19-12 (and other examples in chapter 19) need a rework....

I think there is a slight typo on page 745: ![typo](https://github.com/fluentpython/example-code-2e/assets/17600026/96ed1a1d-1afa-4dfd-97a4-bae97a3c7d54)

Hi Luciano, In chapter 22 you mention that `FrozenJSON.__getattr__()` raising a `KeyError` is "not to confusing". However, today I discovered a side effect from this that __is__ confusing: `copy.copy(FrozenJSON({'name': 'Jim...

`return` in `finally` considered harmful https://github.com/iritkatriel/finally/blob/main/README.md

3e-prep

Hi! I was going through script [explore1.py](https://github.com/fluentpython/example-code-2e/blob/master/22-dyn-attr-prop/oscon/explore1.py) from chapter 22, in particular in the [__init__ method](https://github.com/fluentpython/example-code-2e/blob/master/22-dyn-attr-prop/oscon/explore1.py#L56) and I wrote the following code instead of the code in the script: ```...

I believe the pseudocode for object construction on page 843 is somewhat misleading: ```python def make(the_class, some_arg): new_object = the_class.__new__(some_arg) if isinstance(new_object, the_class): the_class.__init__(new_object, some_arg) return new_object ``` Firstly, it...

## Issue If [`index.search(query)`](https://github.com/fluentpython/example-code-2e/blob/master/21-async/mojifinder/tcp_mojifinder.py#L45) in `tcp_mojifinder.py` returns empty result, it crashes TCP because [`asyncio.StreamWriter.writelines(data)`](https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter.writelines) raises `AssertionError: Data should not be empty` error if `data` is an empty iterable. ### How...

I updated 21-async/mojifinder/tcp_mojifinder.py so search now builds a list of response lines and guards the writelines call, preventing any edge-case crash when there are no matches.