Python version history comparison today. Scraped the releases and decided what version to run my apps on, and what new features to add to them.
3.0 (2008-12-03)
print
statement -> function
dict.iteritems()
-> dict.items()
raw_input()
-> input()
- many things return iterators instead of lists (zip, map, keys, etc)
- unicode string no longer necessary, assumes it
- string formatting, starting to deprecate % and use format
- using
with
for context management
3.1 (2009-06-27)
collections.OrderedDict
added
collections.Counter
added
- unittest can be marked skip and expectedFailure
.format()
can automatically add commas in the thousands places
3.2 (2011-02-20)
- Stable ABI (easier to write extensions across versions)
argparse
replaced optparse
, which only had support for positional args
- logging config by json file
concurrent.futures
for thread/process management
- pyc moved to
__pycache__
- wsgi headers need to be native strings, no encoding
@functools.lru_cache
added
itertools.accumulate()
added
- contextlib now allows contextmanagers to be used as function decorators as well
- can now use a
.pdbrc
3.3 (2012-09-29)
- added
venv
as a stdlib module, for programmatic access from python, as well as command line access via pyvenv
(and then python -m venv
)
- added mock to unittest in stdlib
- added py launcher for windows (double clicking .py automatically runs them)
yield from
to delegate generators
__qualname__
for fully qualified path to that object
3.4 (2014-03-16)
asyncio
added
enum
added
pathlib
added
statistics
added
tracemalloc
added
- pip is shipped with python now, always
3.5 (2015-09-13)
- typing (could use comments and annotation before, but this formalizes)
- coroutines can be used with
async
/ await
syntax (diff syntax before)
- can multiply matrices with
A @ B
instead of dot(A, B)
- much of stdlib reimplemented in C, improving perf significantly
os.scandir()
added (better than the os.walk
function)
math.inf
and math.nan
constants were added
3.6 (2016-12-23)
- f strings
- dicts use 25% less mem
- underscores in numbers
- async generators and async comprehensions
- typing for variable annotations
secrets
module added to stdlib
- asyncio was introduced in 3.4 as provisional but is now declared stable
3.7 (2018-06-27)
- types now have postponed evaluation; basically annotations allow hoisting
breakpoint()
added (internally, this calls sys.breakpointhook()
, which calls pdb.set_trace()
)
- the time module now supports nanoseconds (for most functions)
- typing was introduced in 3.5 as provisional but is now declared stable
- added dataclasses
3.8 (2019-10-14)
- walrus operator
- / in function param means it MUST be positional (can’t be keyword)
- using = in an fstring will insert not just the value of the var but also the name of the var (really helpful for printing and debugging)
- async mocks were added to unittest
3.9 (2020-10-05)
- dict merge | (same as
{**d1, **d2}
) and update |= (same as dict.update
) operators
- graphlib added to stdlib
3.10 (2021-10-04)
- much better error messages in standard exceptions (more specific syntax)
- structural pattern matching (switch statements!)
- type union operator: you can do
int | float
instead of Union[int, float]
- distutils is deprecated, and will be removed in 3.12 (just setuptools now)
3.11 (2022-10-24)
- all around 10-60% faster, average 1.25x, uses slightly more mem tho
- added
tomllib
, can parse toml now with stdlib
- even more specificity in tracebacks, pointing to exact problem
- multiple exceptions can be raised simultaneously in groups
- ton of deprecated stdlib modules and functions removed (none that I really use)