This is a HIGHLY subjective list of new features that I personally find useful when porting programs and libraries to newer versions of Python.
Let me say that again: this list is HIGHLY subjective. Pinch of salt, YMMV, etc.
async
and await
are reserved keywordsdict
is ordered (insertion order)asyncio.run()
and asyncio.create_task()
, as well as
a slew of othersdatetime.fromisoformat()
functools.singledispatch()
hmac.digest()
TextIOWrapper.reconfigure()
socket.close()
subprocess.run(capture_output=True)
{expr=...}
in f-strings\N{name}
in regular expressionsfunctools.lru_cache
without parenthesesfunctools.cached_property()
functools.singledispatchmethod()
Path.link_to()
, but see Path.hardlink_to()
in 3.10shlex.join()
Final
, Literal
, Protocol
, and TypedDict
typing.get_origin()
and typing.get_args()
dict
(dict_a | dict_b
, dict_a |= dict_b
)dict
, list
, etc. can now be used as typing genericsstr.removeprefix()
and str.removesuffix()
__file__
is now an absolute pathPidfdChildWatcher
Callable
, Generator
, Iterable
, Iterator
, etc.os.pidfd_open()
for Linux 5.3+os.waitstatus_to_exitcode()
Path.readlink()
random.randbytes()
socket.send_fds()
and socket.recv_fds()
Annotated
and typing.get_type_hints(include_extras=True)
X | Y
TypeAlias
and ParamSpec
aiter()
and anext()
kw_only=True
)os.eventfd()
and os.splice()
Path.hardlink_to()
and deprecate Path.link_to()
socket.timeout
is now a TimeoutError
for
statementsexc_type
and exc_traceback
dropped from exc_info
start_tls()
timeout()
chdir()
UTC
StrEnum
! ReprEnum
!singledispatch()
understands unions nowcall()
time.sleep()
with nanosecond resolutionassert_never()
, assert_type()
, reveal_type()
dataclass_transform
?LiteralString
Self
! Self
! Self
!TypeVarTuple
?TypedDict
: Required
/NotRequired
Any
can now be subclassed?eager_task_factory()
is all about, maybe pass it to
run()
as a task factoryConfigParser.readfp()
is removed, use readfile()
insteadutcnow()
and utcfromtimestamp()
are deprecated; use now()
and
fromtimestamp()
passing tz=datetime.UTC
insteadcached_property()
no longer locks, let's hope we don't use it anywayitertools.batched()
walk()
relative_to(..., walk_up)
case_sensitive
for glob()
and friendsmake_archive(..., root_dir)
last_exc
for debugging, e.g. in the REPLNamedTemporaryFile(..., delete_on_close=True)
loop.create_unix_server()
automatically removes the socketreplace()
IPv4Address.ipv6_mapped
process_cpu_count()
Path.from_uri()
PurePath.full_match()
PatternError
(renamed from re.error
)exc_type
is deprecatedget_protocol_members()
is_protocol()