Skip to Content
Fluent Python 第2版 ―Pythonicな思考とコーディング手法
book

Fluent Python 第2版 ―Pythonicな思考とコーディング手法

by Luciano Ramalho, 牧野 聡
November 2025
Intermediate to advanced
984 pages
16h 17m
Japanese
O'Reilly Japan, Inc.
Content preview from Fluent Python 第2版 ―Pythonicな思考とコーディング手法

13章インターフェース、プロトコル、ABC

実装に合わせるのではなく、インターフェースに合わせてプログラミングしましょう。

—— Gamma、Helm、Johnson、Vlissides

『First Principle of Object-Oriented Design』†1

[†1] 『Design Patterns: Elements of Reusable Object-Oriented Software』、イントロダクション(18ページ)

オブジェクト指向プログラミングの本質はインターフェースにあります。Pythonでの型を理解するための最善の方法は、「8.4 実行可能な操作が型を決める」でも述べた通り、その型が提供するメソッドつまりインターフェースを知ることです。

プログラミング言語によっては、インターフェースを定義し利用する方法が複数用意されている場合もあります。Python 3.8以降には4つの方法があり、これらを図示したのが図13-1型マップです。簡単にまとめると、以下のようになります。

ダックタイピング
初期からずっと、Pythonでの型に関するデフォルトのアプローチです。本書でも「1章 Pythonのデータモデル」以降で学んできました。
グースタイピング
Python 2.6で採用されたABC(抽象基底クラス)でのアプローチです。実行時に行われるABCへの型チェックに基づいています。この章での主なトピックです。
静的型付け
CやJavaといった静的型付け言語における古典的なアプローチです。Python 3.5からtypingモジュールによってサポートされるようになりました。実際のチェックを行うのは、『PEP 484——Type Hints』(https://fpy.li/pep484 ...
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 ―Pythonicな思考とコーディング手法

Fluent Python ―Pythonicな思考とコーディング手法

Luciano Ramalho, 豊沢 聡, 桑井 博之, 梶原 玲子

Publisher Resources

ISBN: 9784814401284Publisher Website