Skip to Content
Fluent Python, 2ème édition
book

Fluent Python, 2ème édition

by Luciano Ramalho
November 2024
Intermediate to advanced
1014 pages
27h 21m
French
O'Reilly Media, Inc.
Content preview from Fluent Python, 2ème édition

Chapitre 13. Interfaces, protocoles et ABC

Cet ouvrage a été traduit à l'aide de l'IA. Tes réactions et tes commentaires sont les bienvenus : translation-feedback@oreilly.com

Programme une interface, pas une implémentation.

Gamma, Helm, Johnson, Vlissides, premier principe de la conception orientée objet.1

La programmation orientée objet est une question d'interfaces. La meilleure approche pour comprendre un type en Python est de connaître les méthodes qu'il fournit - son interface - comme nous l'avons vu dans "Les types sont définis par les opérations prises en charge"(chapitre 8).

Selon le langage de programmation, nous avons une ou plusieurs façons de définir et d'utiliser les interfaces. Depuis Python 3.8, nous avons quatre façons, qui sont représentées dans lacarte de typage(Figure 13-1). Nous pouvons les résumer ainsi :

Dactylographie le canard

L'approche par défaut de Python en matière de typage depuis le début. Nous étudions le typage des canards depuis le chapitre 1.

Dactylographie l'oie

L'approche soutenue par les classes de base abstraites (ABC) depuis Python 2.6, qui repose sur des vérifications d'exécution des objets par rapport aux ABC. Letypage des oies est un sujet majeur de ce chapitre.

Le typage statique

L'approche traditionnelle des langages à typage statique comme C et Java ; prise en charge depuis Python 3.5 par le module typing, et appliquée par des vérificateurs de type externes conformes à PEP 484-Type Hints. Ce n'est pas le thème de ce chapitre. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Fluent Python

Fluent Python

Luciano Ramalho

Publisher Resources

ISBN: 9798341618954