Download Complete Clean Code in Python Develop maintainable and efficient code 2nd Edition Anaya PDF for All Chapters
Download Complete Clean Code in Python Develop maintainable and efficient code 2nd Edition Anaya PDF for All Chapters
com
https://ebookname.com/product/clean-code-in-python-develop-
maintainable-and-efficient-code-2nd-edition-anaya/
OR CLICK HERE
DOWLOAD NOW
https://ebookname.com/product/python-phrasebook-essential-code-and-
commands-5-print-edition-dayley/
ebookname.com
https://ebookname.com/product/python-mastery-a-code-like-a-pro-guide-
for-python-beginners-1st-edition-jonathan-bates/
ebookname.com
https://ebookname.com/product/2006-international-plumbing-code-1st-
edition-international-code-council-icc-international-code-council/
ebookname.com
https://ebookname.com/product/caliban-s-voice-the-transformation-of-
english-in-post-colonial-literatures-1st-edition-bill-ashcroft/
ebookname.com
The Democratic Promise The Individual Within the Community
First Printing Edition Constance Goh
https://ebookname.com/product/the-democratic-promise-the-individual-
within-the-community-first-printing-edition-constance-goh/
ebookname.com
https://ebookname.com/product/handbook-of-infrared-spectroscopy-of-
ultrathin-films-1st-edition-valeri-p-tolstoy/
ebookname.com
https://ebookname.com/product/adr-in-employment-law-chris-chapman/
ebookname.com
https://ebookname.com/product/mechanisms-of-morphogenesis-1st-edition-
jamie-davies/
ebookname.com
https://ebookname.com/product/the-handbook-of-advanced-materials-
enabling-new-designs-1st-edition-james-k-wessel/
ebookname.com
Buying In The Secret Dialogue Between What We Buy and Who
We Are First Edition Rob Walker
https://ebookname.com/product/buying-in-the-secret-dialogue-between-
what-we-buy-and-who-we-are-first-edition-rob-walker/
ebookname.com
Clean Code in Python
Second Edition
Mariano Anaya
BIRMINGHAM - MUMBAI
Clean Code in Python
Second Edition
Copyright © 2020 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing or its dealers and distributors, will be held liable for any damages caused
or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-80056-021-5
www.packt.com
packt.com
Subscribe to our online digital library for full access to over 7,000 books and videos,
as well as industry leading tools to help you plan your personal development and
advance your career. For more information, please visit our website.
Why subscribe?
• Spend less time learning and more time coding with practical eBooks and
Videos from over 4,000 industry professionals
• Learn better with Skill Plans built especially for you
• Get a free eBook or video every month
• Fully searchable for easy access to vital information
• Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.Packt.com
and as a print book customer, you are entitled to a discount on the eBook copy. Get
in touch with us at [email protected] for more details.
At www.Packt.com, you can also read a collection of free technical articles, sign up
for a range of free newsletters, and receive exclusive discounts and offers on Packt
books and eBooks.
Contributors
Tarek worked at Mozilla for over a decade, building tools and services, leveraging
Python's awesomeness in projects at scale. He now works as a principal engineer
at Elastic.
Table of Contents
Prefaceix
Chapter 1: Introduction, Code Formatting, and Tools 1
Introduction2
The meaning of clean code 2
The importance of having clean code 3
Some exceptions 5
Code formatting 6
Adhering to a coding style guide on your project 6
Documentation9
Code comments 9
Docstrings 10
Annotations 13
Do annotations replace docstrings? 17
Tooling19
Checking type consistency 20
Generic validations in code 22
Automatic formatting 23
Setup for automatic checks 26
Summary28
References28
Chapter 2: Pythonic Code 29
Indexes and slices 30
Creating your own sequences 32
Context managers 34
Implementing context managers 37
Comprehensions and assignment expressions 40
[i]
Table of Contents
[ iv ]
Table of Contents
References282
Chapter 8: Unit Testing and Refactoring 285
Design principles and unit testing 286
A note about other forms of automated testing 287
Unit testing and agile software development 288
Unit testing and software design 289
Defining the boundaries of what to test 293
Tools for testing 293
Frameworks and libraries for unit testing 294
unittest 295
pytest 301
Code coverage 306
Mock objects 309
Refactoring315
Evolving our code 316
Production code isn't the only one that evolves 318
More about testing 319
Property-based testing 320
Mutation testing 320
Common themes in testing 323
Boundaries or limit values 323
Classes of equivalence 323
Edge cases 324
A brief introduction to test-driven development 325
Summary325
References326
Chapter 9: Common Design Patterns 327
Design pattern considerations in Python 328
Design patterns in action 329
Creational patterns 330
Factories 330
Singleton and shared state (monostate) 331
Builder 336
Structural patterns 337
Adapter 337
Composite 339
Decorator 340
Facade 343
Behavioral patterns 344
Chain of responsibility 345
The template method 348
Command 349
State 350
[ vi ]
Table of Contents
[ vii ]
Other documents randomly have
different content
Having beheld these professional curiosities, he left the Mogul
court, and proceeded by the ordinary route towards Bengal. The
Ganges, where he crossed it, in company with Bernier, he found no
larger than the Seine opposite the Louvre, an insignificant stream
which scarcely deserves the name of a river. At Benares he
observed the narrowest streets and the loftiest houses which he had
seen in Hindostan, a circumstance remarked by all travellers, and
among the rest by Heber, who says, “The houses are mostly lofty;
none, I think, less than two stories, most of three, and several of five
or six, a sight which I now for the first time saw in India. The streets,
like those of Chester, are considerably lower than the ground floors
of the houses, which have mostly arched rows in front, with little
shops behind them. Above these the houses are richly embellished
with verandahs, galleries, projecting oriel windows, and very broad
and overhanging coves, supported by carved brackets.” The
opposite sides of the streets stand so near to each other in many
places that they are united by galleries. The number of stone and
brick houses in the city are upwards of twelve thousand, of clay
houses sixteen thousand; and the population in 1803 considerably
exceeded half a million. Benares, according to the Brahmins, forms
no part of the terrestrial globe, but rests upon the thousand-headed
serpent Anarta, or Eternity: or, according to others, on the point of
Siva’s trident, and hence no earthquakes are ever felt there. The
Great Lingam, or Phallies, of Benares, is said to be a petrifaction of
Siva himself; and the worship of this emblem of the godhead so
generally prevails here, that the city contains at least a million
images of the Lingam. This holy city, the Brahmins assure us, was
originally built of gold, but for the sins of mankind it was successively
degraded to stone, and brick, and clay.
From Benares he proceeded through Patna and Rajmahel to
Daca, then a flourishing city; whence, having disposed of numerous
jewels to the nawâb, he returned to Delhi.
To avoid repetitions and perplexing breaks in the narrative, I have
paid no attention to the date of his visits to this or that city; and,
indeed, so confused were his notes and his memory, that he does
not seem to have known very well himself during which of his
journeys many events which he relates took place. Into the
particulars of his voyage to Ceylon, Sumatra, and Java it is
unnecessary to enter, more full and curious accounts of those
islands occurring in other travellers.
On his return to France from his fifth visit to the East, he married
an ancient damsel, to borrow an epithet from Burke, merely from
gratitude to her father, who was a jeweller, and had rendered him
several essential services. After this he undertook one more journey
into Asia, with merchandise to the value of four hundred thousand
livres, consisting of curious clocks, crystal and agate vases, pearls,
and other jewelry. This expedition occupied him six years, during
which he advanced farther towards the east than he had hitherto
done; and having in this and his other journeys amassed
considerable wealth, he returned with a splendid assortment of
diamonds to France, having been engaged upwards of forty years in
travelling. Disposing of these jewels advantageously to the French
king, who granted him a patent of nobility, he now conceived that all
his wanderings were at an end, and began to think of enjoying the
wealth he had purchased with so much time and toil and difficulty.
Experience, however, had not rendered him wise. Puffed up with the
vanity inspired by his patent of nobility, his whole soul was now
wrapped up in visions of luxury and magnificence. He rented a
splendid house, set up a carriage, and hired a number of valets. The
nobility, who no doubt devoured his adventures and his dinners with
equal greediness, flocked about him, invited, caressed, flattered, and
ruined him.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com