PyCon JP 2020 の「Python 3.9 時代の型安全な Python の極め方」の発表資料です
![Python 3.9 時代の型安全な Pythonの極め方 / Mastering Type Safety in Python 3.9 Era](https://cdn-ak-scissors.b.st-hatena.com/image/square/5dc58dd4ac85a6da57117e4a0b7f0d1aa748876a/height=288;version=1;width=512/https%3A%2F%2Ffiles.speakerdeck.com%2Fpresentations%2Fb09f81727b934f9aa41d07a9d8c1a0c3%2Fslide_0.jpg%3F16124346)
decimal — Decimal fixed-point and floating-point arithmetic¶ Source code: Lib/decimal.py The decimal module provides support for fast correctly rounded decimal floating-point arithmetic. It offers several advantages over the float datatype: Decimal “is based on a floating-point model which was designed with people in mind, and necessarily has a paramount guiding principle – computers must provide
Floating Point Math Your language isn’t broken, it’s doing floating point math. Computers can only natively store integers, so they need some way of representing decimal numbers. This representation is not perfectly accurate. This is why, more often than not, 0.1 + 0.2 != 0.3. Why does this happen? It’s actually rather interesting. When you have a base-10 system (like ours), it can only express fr
First steps Getting started Type hints cheat sheet Using mypy with an existing codebase Type system reference Built-in types Type inference and type annotations Kinds of types Class basics Annotation issues at runtime Protocols and structural subtyping Dynamically typed code Type narrowing Duck type compatibility Stub files Generics More types Literal types and Enums TypedDict Final names, methods
みなさん Cython 使ってますか?私は使っていません. というのも次の理由があったからです. コンパイルが面倒... C じゃなくて Python が書きたいんだけど... Python のコードを実行不可にしたくない or デコレータが見にくい... これらのうち上記2つはこれまでも解決されていました. IPython の Cython Magic を使う Pure Python Mode を使う 最後の一つに関しては先日 Cython 0.27 によって解決されました。 Variable Annotation を使う Python は v.3.5 より Type Hints (PEP 484) が追加され, v.3.6 より Variable Annotation (PEP 526) が追加されました. そして, 現在最新版である Cython 0.27 より Variable A
Pythonへの型アノテーション導入を目指すGuido van Rossum氏 mypy の型アノテーションの構文を Python に取り込もうとメーリングリストで提案したニュースが話題になりました。今夏に話題になったニュースを今冬にフォローするという季節外れ感ですが、ずっと興味はあって「あとで読む」状態になっていたのを調べてみました。 基本的には mypy のドキュメントから自分の興味のあるところをかいつまんで説明しています。分かりにくいところがあれば原文を参照してください。 Welcome to Mypy documentation! mypy とは mypy は Python の静的型チェッカー (static type checker) です。wikipedia:静的コード解析 や wikipedia:en:Lint (software) ツールの一種だと説明されています。 Pyt
PEP 484 – Type Hints Author: Guido van Rossum <guido at python.org>, Jukka Lehtosalo <jukka.lehtosalo at iki.fi>, Łukasz Langa <lukasz at python.org> BDFL-Delegate: Mark Shannon Discussions-To: Python-Dev list Status: Final Type: Standards Track Topic: Typing Created: 29-Sep-2014 Python-Version: 3.5 Post-History: 16-Jan-2015, 20-Mar-2015, 17-Apr-2015, 20-May-2015, 22-May-2015 Resolution: Python-De
Compile-time type checking Static typing makes it easier to find bugs with less debugging. Easier maintenance Type declarations act as machine-checked documentation. Static typing makes your code easier to understand and easier to modify without introducing bugs. Grow your programs from dynamic to static typing You can develop programs with dynamic typing and add static typing after your code has
$ mypy test.py test.py: note: In function "func": test.py:2: error: Incompatible return value type (got "str", expected "int") アノテーションを元に型をチェックして、戻り値の型がintなのにstrを返しているのでエラーになります。 やっていく気持ち "mypyやっていく"というのは、PEP 484に対応した型アノテーションを付け、mypyを実行し静的チェックをパスすることを指します。なぜやっていく気持ちになったかというと、Static types in Python, oh my(py)! この記事を読んだことが大きいです。やっていけそうな気がしました。担当している案件が規模が大きく既存機能の変更頻度も高いものだったので、信頼できる型アノテーションが有ると、修正する
The Type Hierarchy¶ SQLAlchemy provides abstractions for most common database data types, as well as several techniques for customization of datatypes. Database types are represented using Python classes, all of which ultimately extend from the base type class known as TypeEngine. There are two general categories of datatypes, each of which express themselves within the typing hierarchy in differe
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く