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な思考とコーディング手法

8章関数での型ヒント

Pythonはこれからも動的に型付けされる言語であり続けます。我々は型ヒントを強制するつもりはなく、型ヒントを慣習化するようなこともありません」ということを強調しておきたいと思います。

—— Guido van Rossum、Jukka Lehtosalo、Łukasz Langa

『PEP 484——Type Hints』†1

[†1] 『PEP 484——Type Hints』(https://fpy.li/8-1)の『Rationale and Goals』の節から引用しました。太字は原文のまま。

2001年にPython 2.2で型とクラスが統一(https://fpy.li/descr101)されて以来の大きな変更が、この章で解説する型ヒントです。ただし、すべてのPythonユーザーが等しくそのメリットを享受できるわけではありません。型ヒントが必須ではないのはこのためです。

『PEP 484——Type Hints』(https://fpy.li/pep484)で、関数の引数や戻り値、変数について明示的な型宣言を行うための構文とその意味が定義されています。開発者ツールが静的解析を通じて(つまり、実際にコードを実行してテストしなくても)バグを発見しやすくすることが目的です。

主に恩恵を受けるのは、IDE(統合開発環境)やCI(継続的インテグレーション)を行うプロのソフトウェアエンジニアです。このグループの人々にとっては魅力的ですが、このメリットはすべてのPythonユーザーに当てはまるわけではありません。

むしろ、Pythonユーザーの大多数を占めるのは、このグループ以外の人々です。科学者、トレーダー、アーティスト、職人、アナリスト、さまざまな分野の学生、その他大勢の人々がいます。彼らのほとんどにとっては、(すでに静的型付けや派生型、ジェネリクスといった概念を持つ言語に慣れ親しんでいるのでもなければ)型ヒントを学ぶコストは高いでしょう。また、多くのチームではコードの規模はささほど大きくなく、構成メンバーも少数あるいは1人だけです。このようなチームに型ヒントを導入するメリットはあまり大きくありません。データサイエンスや創作活動、学習などで、データあるいはアイデアの探求のためにコードを書くという場合には、Pythonでのデフォルトである動的型付けを活用するほうが表現力が高くシンプルです。 ...

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, 豊沢 聡, 桑井 博之, 梶原 玲子
Architecture Patterns with Python

Architecture Patterns with Python

Harry Percival, Bob Gregory

Publisher Resources

ISBN: 9784814401284Publisher Website