Skip to content

Conversation

@eumiro
Copy link
Contributor

@eumiro eumiro commented Jan 31, 2021

Hi Luciano, I have some random cleanups for your repository. Sorry for the single commit. Please ask for any details/reasons in my PR.

Generally, most updates can be grouped in following categories:

  • f-strings everywhere
  • some pep8-ish reformatting
  • fix some typos
  • math.floor returns int in Python 3, no need to convert it
  • removal of unused imports

Looking forward to your feedback!

@ramalho ramalho merged commit 33f73a1 into fluentpython:master Feb 13, 2021
@ramalho
Copy link
Member

ramalho commented Feb 13, 2021

Thank you so much, @eumiro !

@ramalho
Copy link
Member

ramalho commented Feb 13, 2021

In a few places where I used math.floor, I had an expression like math.floor(math.sqrt(n)).

It turns out Python 3.8 added a math.isqrt function that does what I needed, so that's even more modern!

I would not have found it if you didn't make me look at that code again. Thanks!

@eumiro eumiro deleted the py36plus branch February 13, 2021 15:56
@eumiro
Copy link
Contributor Author

eumiro commented Feb 13, 2021

That's a very good point. It depends on where you officially “pin” your book. When I write a new project where I control the whole environment, then I'd go with Python 3.9 (and use that math.isqrt happily). On the other hand, if I write a library and want to offer modern code to my users, I'd go currently (February 2021) with Python 3.6–3.9 and therefore without math.isqrt.

That's exactly the reason why this PR aimed for Python 3.6+. Next year I'd aim for 3.7+ and start using dataclasses.

@ramalho
Copy link
Member

ramalho commented Feb 13, 2021

For the book, I aim for the latest official release—that was also my policy in the first edition.

The upsides are showing the readers new features they may not know about, and making the book as fresh as possible, given that updates are difficult in the traditional editorial process of book publishing.

The downside is minimal: the programs are all very short, so fixing for incompatibilities of that kind is easy. The top reason I see for readers to use 3.7 at the moment is to run the examples with Pypy.

BTW, as soon as Mypy 0.800 started accepting generic built-ins (like list[int]) I started removing all redundant imports like from typing import List, Tuple, Dict etc. I added a note about that matter in the first occurrence (in Chapter 5) and that's it. I think that's a good usability improvement for typing. There was already a whole section about that issue in Chapter 8. The difference is that now I assume Python 3.9 and Mypy 0.800 in the code examples that use generics.

rct pushed a commit to rct/book-fluent-python-2e-code that referenced this pull request Feb 5, 2024
* Init ch05 notebook

* Additions to ch05 notebook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants