Skip to content

Commit 0897a6c

Browse files
committed
Merge branch 'function-to-callable'
Rename typing.Function to Callable
2 parents 9d41171 + 081c484 commit 0897a6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+673
-673
lines changed

docs/source/kinds_of_types.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ Callable types (and lambdas)
6464

6565
You can pass around function objects and bound methods in statically
6666
typed code. The type of a function that accepts arguments ``A1``, |...|, ``An``
67-
and returns ``Rt`` is ``Function[[A1, ..., An], Rt]``. Example:
67+
and returns ``Rt`` is ``Callable[[A1, ..., An], Rt]``. Example:
6868

6969
.. code-block:: python
7070
71-
def twice(i: int, next: Function[[int], int]) -> int:
71+
def twice(i: int, next: Callable[[int], int]) -> int:
7272
return next(next(i))
7373
7474
def add(i: int) -> int:

lib-python/3.2/fnmatch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import re
1515
import functools
1616

17-
from typing import Iterable, List, AnyStr, Any, Function, Match
17+
from typing import Iterable, List, AnyStr, Any, Callable, Match
1818

1919
__all__ = ["filter", "fnmatch", "fnmatchcase", "translate"]
2020

@@ -39,7 +39,7 @@ def fnmatch(name: AnyStr, pat: AnyStr) -> bool:
3939

4040
@functools.lru_cache(maxsize=250)
4141
def _compile_pattern(pat: AnyStr,
42-
is_bytes: bool = False) -> Function[[AnyStr],
42+
is_bytes: bool = False) -> Callable[[AnyStr],
4343
Match[AnyStr]]:
4444
if isinstance(pat, bytes):
4545
pat_str = str(pat, 'ISO-8859-1')

lib-python/3.2/random.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from hashlib import sha512 as _sha512
4646

4747
from typing import (
48-
Any, typevar, Iterable, Sequence, List, Function, Set, cast, SupportsInt, Union
48+
Any, typevar, Iterable, Sequence, List, Callable, Set, cast, SupportsInt, Union
4949
)
5050

5151
__all__ = ["Random","seed","random","uniform","randint","choice","sample",
@@ -170,7 +170,7 @@ def __reduce__(self) -> object:
170170
## -------------------- integer methods -------------------
171171

172172
def randrange(self, start: SupportsInt, stop: SupportsInt = None,
173-
step: int = 1, int: Function[[SupportsInt],
173+
step: int = 1, int: Callable[[SupportsInt],
174174
int] = int) -> int:
175175
"""Choose a random item from range(start, stop[, step]).
176176
@@ -222,9 +222,9 @@ def randint(self, a: int, b: int) -> int:
222222

223223
return self.randrange(a, b+1)
224224

225-
def _randbelow(self, n: int, int: Function[[float], int] = int,
225+
def _randbelow(self, n: int, int: Callable[[float], int] = int,
226226
maxsize: int = 1<<BPF,
227-
type: Function[[object], type] = type,
227+
type: Callable[[object], type] = type,
228228
Method: type = _MethodType,
229229
BuiltinMethod: type = _BuiltinMethodType) -> int:
230230
"Return a random int in the range [0,n). Raises ValueError if n==0."
@@ -264,8 +264,8 @@ def choice(self, seq: Sequence[T]) -> T:
264264
return seq[i]
265265

266266
def shuffle(self, x: List[T],
267-
random: Function[[], float] = None,
268-
int: Function[[float], int] = int) -> None:
267+
random: Callable[[], float] = None,
268+
int: Callable[[float], int] = int) -> None:
269269
"""x, random=random.random -> shuffle list x in place; return None.
270270
271271
Optional arg random is a 0-argument function returning a random

lib-python/3.2/shutil.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import builtins
1616

1717
from typing import (
18-
Any, AnyStr, IO, List, Iterable, Function, Tuple, Dict, Sequence, cast,
18+
Any, AnyStr, IO, List, Iterable, Callable, Tuple, Dict, Sequence, cast,
1919
Traceback
2020
)
2121

@@ -159,7 +159,7 @@ def copy2(src: str, dst: str) -> None:
159159
copyfile(src, dst)
160160
copystat(src, dst)
161161

162-
def ignore_patterns(*patterns: str) -> Function[[str, List[str]],
162+
def ignore_patterns(*patterns: str) -> Callable[[str, List[str]],
163163
Iterable[str]]:
164164
"""Function that can be used as copytree() ignore parameter.
165165
@@ -173,8 +173,8 @@ def _ignore_patterns(path: str, names: List[str]) -> Iterable[str]:
173173
return _ignore_patterns
174174

175175
def copytree(src: str, dst: str, symlinks: bool = False,
176-
ignore: Function[[str, List[str]], Iterable[str]] = None,
177-
copy_function: Function[[str, str], None] = copy2,
176+
ignore: Callable[[str, List[str]], Iterable[str]] = None,
177+
copy_function: Callable[[str, str], None] = copy2,
178178
ignore_dangling_symlinks: bool = False) -> None:
179179
"""Recursively copy a directory tree.
180180
@@ -257,7 +257,7 @@ def copytree(src: str, dst: str, symlinks: bool = False,
257257
raise Error(errors)
258258

259259
def rmtree(path: str, ignore_errors: bool = False,
260-
onerror: Function[[Any, str, Tuple[type, BaseException, Traceback]],
260+
onerror: Callable[[Any, str, Tuple[type, BaseException, Traceback]],
261261
None] = None) -> None:
262262
"""Recursively delete a directory tree.
263263

lib-python/3.2/subprocess.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class Popen(args, bufsize=0, executable=None,
348348
import errno
349349

350350
from typing import (
351-
Any, Tuple, List, Sequence, Undefined, Function, Mapping, cast, Set, Dict,
351+
Any, Tuple, List, Sequence, Undefined, Callable, Mapping, cast, Set, Dict,
352352
IO, TextIO, Traceback, AnyStr
353353
)
354354

@@ -650,7 +650,7 @@ class Popen(object):
650650
def __init__(self, args: Sequence[Any], bufsize: int = 0,
651651
executable: str = None, stdin: Any = None,
652652
stdout: Any = None, stderr: Any = None,
653-
preexec_fn: Function[[], Any] = None,
653+
preexec_fn: Callable[[], Any] = None,
654654
close_fds: Any = _PLATFORM_DEFAULT_CLOSE_FDS,
655655
shell: int = False, cwd: str = None,
656656
env: Mapping[str, str] = None,
@@ -924,7 +924,7 @@ def _find_w9xpopen(self) -> str:
924924

925925

926926
def _execute_child(self, args: Sequence[str], executable: str,
927-
preexec_fn: Function[[], Any], close_fds: Any,
927+
preexec_fn: Callable[[], Any], close_fds: Any,
928928
pass_fds: Any, cwd: str, env: Mapping[str, str],
929929
universal_newlines: int,
930930
startupinfo: STARTUPINFO, creationflags: int,
@@ -1021,10 +1021,10 @@ def _internal_poll(self, _deadstate: int = None) -> int:
10211021
from _subprocess import Handle
10221022

10231023
def _internal_poll_win(self, _deadstate: int = None,
1024-
_WaitForSingleObject: Function[[Handle, int], int] =
1024+
_WaitForSingleObject: Callable[[Handle, int], int] =
10251025
_subprocess.WaitForSingleObject,
10261026
_WAIT_OBJECT_0: int = _subprocess.WAIT_OBJECT_0,
1027-
_GetExitCodeProcess: Function[[Handle], int] =
1027+
_GetExitCodeProcess: Callable[[Handle], int] =
10281028
_subprocess.GetExitCodeProcess) -> int:
10291029
if self.returncode is None:
10301030
if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
@@ -1170,7 +1170,7 @@ def _close_fds(self, fds_to_keep: Set[int]) -> None:
11701170

11711171

11721172
def _execute_child(self, args: Sequence[str], executable: str,
1173-
preexec_fn: Function[[], Any], close_fds: Any,
1173+
preexec_fn: Callable[[], Any], close_fds: Any,
11741174
pass_fds: Any, cwd: str, env: Mapping[str, str],
11751175
universal_newlines: int,
11761176
startupinfo: 'STARTUPINFO', creationflags: int,
@@ -1400,10 +1400,10 @@ def _dup2(a: int, b: int) -> None:
14001400

14011401
def _handle_exitstatus(
14021402
self, sts: int,
1403-
_WIFSIGNALED: Function[[int], bool] = os.WIFSIGNALED,
1404-
_WTERMSIG: Function[[int], bool] = os.WTERMSIG,
1405-
_WIFEXITED: Function[[int], bool] = os.WIFEXITED,
1406-
_WEXITSTATUS: Function[[int], bool] = os.WEXITSTATUS) -> None:
1403+
_WIFSIGNALED: Callable[[int], bool] = os.WIFSIGNALED,
1404+
_WTERMSIG: Callable[[int], bool] = os.WTERMSIG,
1405+
_WIFEXITED: Callable[[int], bool] = os.WIFEXITED,
1406+
_WEXITSTATUS: Callable[[int], bool] = os.WEXITSTATUS) -> None:
14071407
# This method is called (indirectly) by __del__, so it cannot
14081408
# refer to anything outside of its local scope."""
14091409
if _WIFSIGNALED(sts):
@@ -1426,7 +1426,7 @@ def _internal_poll(self, _deadstate: int = None) -> int:
14261426
return self._internal_poll_posix(_deadstate)
14271427

14281428
def _internal_poll_posix(self, _deadstate: int = None,
1429-
_waitpid: Function[[int, int],
1429+
_waitpid: Callable[[int, int],
14301430
Tuple[int, int]] = os.waitpid,
14311431
_WNOHANG: int = os.WNOHANG,
14321432
_os_error: Any = os.error) -> int:

lib-python/3.2/tempfile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from random import Random as _Random
3838

3939
from typing import (
40-
Any as _Any, Function as _Function, Iterator as _Iterator,
40+
Any as _Any, Callable as _Callable, Iterator as _Iterator,
4141
Undefined as _Undefined, List as _List, Tuple as _Tuple, Dict as _Dict,
4242
Iterable as _Iterable, IO as _IO, ducktype as _ducktype,
4343
Traceback as _Traceback
@@ -62,7 +62,7 @@ def _set_cloexec(fd: int) -> None:
6262

6363
try:
6464
import _thread
65-
_allocate_lock = _thread.allocate_lock # type: _Function[[], _Any]
65+
_allocate_lock = _thread.allocate_lock # type: _Callable[[], _Any]
6666
except ImportError:
6767
import _dummy_thread
6868
_allocate_lock = _dummy_thread.allocate_lock
@@ -89,7 +89,7 @@ def _set_cloexec(fd: int) -> None:
8989
_once_lock = _allocate_lock()
9090

9191
if hasattr(_os, "lstat"):
92-
_stat = _os.lstat # type: _Function[[str], object]
92+
_stat = _os.lstat # type: _Callable[[str], object]
9393
elif hasattr(_os, "stat"):
9494
_stat = _os.stat
9595
else:

lib-python/3.2/test/test_fnmatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from fnmatch import fnmatch, fnmatchcase, translate, filter
77

8-
from typing import Any, AnyStr, Function
8+
from typing import Any, AnyStr, Callable
99

1010
class FnmatchTestCase(unittest.TestCase):
1111

lib-python/3.2/test/test_posixpath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from posixpath import realpath, abspath, dirname, basename
1414

1515
import posix
16-
from typing import Any, typevar, Function
16+
from typing import Any, typevar, Callable
1717

1818
T = typevar('T')
1919

@@ -23,7 +23,7 @@
2323
ABSTFN = abspath(support.TESTFN)
2424

2525
def skip_if_ABSTFN_contains_backslash(
26-
test: Function[[T], None]) -> Function[[T], None]:
26+
test: Callable[[T], None]) -> Callable[[T], None]:
2727
"""
2828
On Windows, posixpath.abspath still returns paths with backslashes
2929
instead of posix forward slashes. If this is the case, several tests

lib-python/3.2/test/test_pprint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import collections
77
import itertools
88

9-
from typing import List, Any, Dict, Tuple, cast, Undefined, Function
9+
from typing import List, Any, Dict, Tuple, cast, Undefined, Callable
1010

1111
# list, tuple and dict subclasses that do or don't overwrite __repr__
1212
class list2(list):
@@ -456,7 +456,7 @@ def test_sort_unorderable_values(self) -> None:
456456
keys = [Unorderable() for i in range(n)]
457457
random.shuffle(keys)
458458
skeys = sorted(keys, key=id)
459-
clean = Undefined(Function[[str], str])
459+
clean = Undefined(Callable[[str], str])
460460
clean = lambda s: s.replace(' ', '').replace('\n','')
461461

462462
self.assertEqual(clean(pprint.pformat(set(keys))),

lib-python/3.2/test/test_random.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from math import log, exp, pi, fsum, sin
99
from test import support
1010

11-
from typing import Undefined, Any, Dict, List, Function, Generic, typevar
11+
from typing import Undefined, Any, Dict, List, Callable, Generic, typevar
1212

1313
RT = typevar('RT', values=(random.Random, random.SystemRandom))
1414

@@ -219,8 +219,8 @@ def test_genrandbits(self) -> None:
219219
self.assertRaises(ValueError, self.gen.getrandbits, -1)
220220
self.assertRaises(TypeError, self.gen.getrandbits, 10.1)
221221

222-
def test_randbelow_logic(self, _log: Function[[float, float], float] = log,
223-
int: Function[[float], int] = int) -> None:
222+
def test_randbelow_logic(self, _log: Callable[[float, float], float] = log,
223+
int: Callable[[float], int] = int) -> None:
224224
# check bitcount transition points: 2**i and 2**(i+1)-1
225225
# show that: k = int(1.001 + _log(n, 2))
226226
# is equal to or one greater than the number of bits in n
@@ -388,8 +388,8 @@ def test_genrandbits(self) -> None:
388388
self.assertRaises(ValueError, self.gen.getrandbits, -1)
389389

390390
def test_randbelow_logic(self,
391-
_log: Function[[int, float], float] = log,
392-
int: Function[[float], int] = int) -> None:
391+
_log: Callable[[int, float], float] = log,
392+
int: Callable[[float], int] = int) -> None:
393393
# check bitcount transition points: 2**i and 2**(i+1)-1
394394
# show that: k = int(1.001 + _log(n, 2))
395395
# is equal to or one greater than the number of bits in n

lib-python/3.2/test/test_shutil.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from test.support import check_warnings, captured_stdout
2525

2626
from typing import (
27-
Any, Function, Tuple, List, Sequence, BinaryIO, overload, Traceback, IO,
27+
Any, Callable, Tuple, List, Sequence, BinaryIO, overload, Traceback, IO,
2828
ducktype
2929
)
3030

@@ -129,7 +129,7 @@ def test_on_error(self) -> None:
129129
# Clean up.
130130
shutil.rmtree(TESTFN)
131131

132-
def check_args_to_onerror(self, func: Function[[str], Any], arg: str,
132+
def check_args_to_onerror(self, func: Callable[[str], Any], arg: str,
133133
exc: Tuple[type, BaseException,
134134
Traceback]) -> None:
135135
# test_rmtree_errors deliberately runs rmtree
@@ -409,7 +409,7 @@ def test_copytree_dangling_symlinks(self) -> None:
409409
self.assertIn('test.txt', os.listdir(dst_dir))
410410

411411
def _copy_file(self,
412-
method: Function[[str, str], None]) -> Tuple[str, str]:
412+
method: Callable[[str, str], None]) -> Tuple[str, str]:
413413
fname = 'test.txt'
414414
tmpdir = self.mkdtemp()
415415
self.write_file([tmpdir, fname])

lib-python/3.2/test/test_subprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import resource
1919

20-
from typing import Any, Dict, Function, Iterable, List, Set, Tuple
20+
from typing import Any, Dict, Callable, Iterable, List, Set, Tuple
2121

2222
mswindows = (sys.platform == "win32")
2323

lib-typing/2.7/test_typing.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from typing import (
66
List, Dict, Set, Tuple, Pattern, BytesPattern, Match, BytesMatch, Any,
7-
Function, Generic, AbstractGeneric, Protocol, Sized, Iterable, Iterator,
7+
Callable, Generic, AbstractGeneric, Protocol, Sized, Iterable, Iterator,
88
Sequence, AbstractSet, Mapping, BinaryIO, TextIO, SupportsInt, SupportsFloat,
99
SupportsAbs, Reversible, Undefined, cast, forwardref, overload, typevar
1010
)
@@ -48,11 +48,11 @@ def test_Any(self):
4848
s = u'x'
4949
self.assertIs(Any(s), s)
5050

51-
def test_Function(self):
52-
# Just check that we can call Function. Don't care about return value.
53-
Function[[], int]
54-
Function[[int], None]
55-
Function[[int, unicode], bool]
51+
def test_Callable(self):
52+
# Just check that we can call Callable. Don't care about return value.
53+
Callable[[], int]
54+
Callable[[int], None]
55+
Callable[[int, unicode], bool]
5656

5757
def test_cast(self):
5858
o = object()

lib-typing/2.7/typing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
'Any',
1515
'AnyStr',
1616
'Dict',
17-
'Function',
17+
'Callable',
1818
'Generic',
1919
'GenericMeta',
2020
'IO',
@@ -146,7 +146,7 @@ def __getitem__(self, typeargs):
146146
Dict = TypeAlias(dict)
147147
Set = TypeAlias(set)
148148
Tuple = TypeAlias(tuple)
149-
Function = TypeAlias(callable)
149+
Callable = TypeAlias(callable)
150150
Pattern = TypeAlias(type(re.compile('')))
151151
Match = TypeAlias(type(re.match('', '')))
152152

0 commit comments

Comments
 (0)