summaryrefslogtreecommitdiffstats
path: root/Doc/whatsnew
diff options
context:
space:
mode:
authorYurii Karabas <1998uriyyo@gmail.com>2022-04-19 02:50:59 (GMT)
committerGitHub <noreply@github.com>2022-04-19 02:50:59 (GMT)
commit014eb7fd0242963ac475abb3c1fb9be0714b203f (patch)
tree164fbb63b9c45c636da5c5f37433bdf16e3b02ed /Doc/whatsnew
parent6fdb62b1fa344b9cdf1f221eac83404fb1980822 (diff)
downloadcpython-014eb7fd0242963ac475abb3c1fb9be0714b203f.zip
cpython-014eb7fd0242963ac475abb3c1fb9be0714b203f.tar.gz
cpython-014eb7fd0242963ac475abb3c1fb9be0714b203f.tar.bz2
bpo-46014: Add docs regarding `functools.singledispatch` changes in 3.11 (#32282)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r--Doc/whatsnew/3.11.rst30
1 files changed, 30 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index baff687..6540a25 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -267,6 +267,36 @@ fractions
that an ``isinstance(some_fraction, typing.SupportsInt)`` check passes.
(Contributed by Mark Dickinson in :issue:`44547`.)
+functools
+---------
+
+* :func:`functools.singledispatch` now supports :data:`types.UnionType`
+ and :data:`typing.Union` as annotations to the dispatch argument.::
+
+ >>> from functools import singledispatch
+ >>> @singledispatch
+ ... def fun(arg, verbose=False):
+ ... if verbose:
+ ... print("Let me just say,", end=" ")
+ ... print(arg)
+ ...
+ >>> @fun.register
+ ... def _(arg: int | float, verbose=False):
+ ... if verbose:
+ ... print("Strength in numbers, eh?", end=" ")
+ ... print(arg)
+ ...
+ >>> from typing import Union
+ >>> @fun.register
+ ... def _(arg: Union[list, set], verbose=False):
+ ... if verbose:
+ ... print("Enumerate this:")
+ ... for i, elem in enumerate(arg):
+ ... print(i, elem)
+ ...
+
+ (Contributed by Yurii Karabas in :issue:`46014`.)
+
hashlib
-------