This commit is contained in:
Correl Roush 2020-10-09 01:56:12 -04:00
parent 8e62f7175c
commit 2b7ce615ec
5 changed files with 40 additions and 10 deletions

View file

@ -0,0 +1,6 @@
#+title: Trans Flag
* Colors
- Maya Blue :: Hex: =#55CDFC=, RGB: =(85, 205, 252)=, CMYK: =0.662, 0.186, 0, 0.011=
- White :: Hex: =#FFFFFF=, RGB: =(255, 255, 255)=, CMYK: =0, 0, 0, 0=
- Amaranth Pink :: Hex: =#F7A8B8=, RGB: =(247, 168, 184)=, CMYK: =0, 0.319, 0.255, 0.031=

View file

@ -1,10 +1,12 @@
#+title: Python Typing
#+LINK: pep https://www.python.org/dev/peps/pep-%s/
Python does not require nor enforce strict typing, and instead takes a dynamic
approach using [[file:20201008164244-duck_typing.org][Duck Typing]].
Optional [[file:20201008164835-structural_typing.org][Structural Typing]] support for Python is provided via type hints as
described in [[https://www.python.org/dev/peps/pep-0484/][PEP-484]].
Optional [[file:20201009010321-static_type_checking.org][Static Type Checking]] support for Python is provided via type hints as
described in [[pep:0484][PEP-484]] (which covers [[file:20201009010657-nominal_typing.org][Nominal Typing]]) and expanded upon in [[pep:0544][PEP-544]]
(which covers [[file:20201008164835-structural_typing.org][Structural Typing]]).
Variables, function arguments, and return values can have their types annotated,
e.g. "variable x has type integer" or "function y takes a string and returns a
@ -22,4 +24,20 @@ program correctness.
- Type hints do not guarantee purity.
- Type hints are not checked at run-time.
* Fun facts
- Python's =boolean= inherits from =int=, hence =True + True = 2=.
- Per [[pep:0285][PEP-285]], Python's =boolean= inherits from =int=, hence =True + True = 2=.
* Relevant PEPs
- [[pep:0482][PEP 482 -- Literature Overview for Type Hints]]
- [[pep:0483][PEP 483 -- The Theory of Type Hints]]
- [[pep:0484][PEP 484 -- Type Hints]]
- [[pep:0526][PEP 526 -- Syntax for Variable Annotations]]
- [[pep:0544][PEP 544 -- Protocols: Structural subtyping (static duck typing)]]
- [[pep:0557][PEP 557 -- Data Classes]]
- [[pep:0560][PEP 560 -- Core support for typing module and generic types]]
- [[pep:0561][PEP 561 -- Distributing and Packaging Type Information]]
- [[pep:0563][PEP 563 -- Postponed Evaluation of Annotations]]
- [[pep:0585][PEP 585 -- Type Hinting Generics In Standard Collections]]
- [[pep:0586][PEP 586 -- Literal Types]]
- [[pep:0589][PEP 589 -- TypedDict: Type Hints for Dictionaries with a Fixed Set of Keys]]
- [[pep:0591][PEP 591 -- Adding a final qualifier to typing]]
- [[pep:0604][PEP 604 -- Allow writing union types as X | Y]]
- [[pep:0613][PEP 613 -- Explicit Type Aliases]]

View file

@ -10,10 +10,5 @@ types are equivalent and whether a type is a subtype of another.
--- https://en.wikipedia.org/wiki/Structural_type_system
#+end_quote
* Benefits
** Easier reasoning
Types make it easier to reason about code, as they describe succinctly what a
function can do. If a function takes a single string as an argument and returns an integer, there's only so many things
** Error reduction
While types are not a substitute for testing, they do obviate a class of tests
that you have to write yourself.
Structural type systems can achieve [[file:20201009010321-static_type_checking.org][static]] [[file:20201008164244-duck_typing.org][Duck Typing]], in that a type's
structure is what determines its suitability, not its name.

View file

@ -0,0 +1 @@
#+title: Static Type Checking

View file

@ -0,0 +1,10 @@
#+title: Nominal Typing
#+begin_quote
Nominal typing means that two variables are type-compatible if and only if their
declarations name the same type. For example, in C, two struct types with
different names in the same translation unit are never considered compatible,
even if they have identical field declarations.
--- https://en.wikipedia.org/wiki/Nominal_type_system
#+end_quote