Overview
Syllabus
Getting Started with Statically Typed Programming in Python 3.10
Let's start with function definitions Nothing too difficult Just write type . After the arguments, write colon and the type . Before the colon at the end of the function definition write an arrow and the type
Escaping from complex type puzzles • Any can hold instances of any type • It's better not to use it • Import and use from typing when necessary
Using types from collections.abc differently • There are many types in collections.abe" . It's better to use a collection with a few methods to increase portability • Ex. 'Iterable is better than "list • It's a good idea to look at the methods used in your functions The figure on the next page shows the relationship...
The differences between tuple and other Sequences • tuple' is fixed up to the length of information • Specify the type for the number of elements . Or you can mix types, such as tuple int
A sequence, such as a list has the same constraint for all elements . Can be used regardless of the length of the Sequence by setting only one
User-defined Generic types Example: a generic mapping type
What is the future. module? . Using typing new feature in the older versions, write
New Features on Type Hints in 3.10 • PEP 504: New Type Union Operator • PEP 512 Parameter Specification Variables
PEP 612: Parameter Specification Variables Motivation Needed a way to represent a function that has the same arguments as the specified function
PEP 647: User-Defined Type Guards Motivation • Type checker tools use a technique called type narrowing to determine the type of information
New Feature on Type Hints in 3.11 Python 3.11 is focused on performance tuning but there are also new features in Typing
Summary 1. Benefits, starting with def , Built-in types 2. Standard collections since 39 3. Collections, Union, Optional Callable. User-defined Generics
Taught by
PyCon US