Skip to content

Commit 5f5250e

Browse files
committed
Merge pull request #665 from kirbyfan64/stub-fixes
Remove some uses of overload
2 parents 42b9328 + d0ff77b commit 5f5250e

File tree

7 files changed

+25
-81
lines changed

7 files changed

+25
-81
lines changed

stubs/3.2/fnmatch.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,9 @@
33
# Based on http://docs.python.org/3.2/library/fnmatch.html and
44
# python-lib/fnmatch.py
55

6-
from typing import overload, Iterable, List
6+
from typing import Iterable, List, AnyStr
77

8-
@overload
9-
def fnmatch(name: str, pat: str) -> bool: pass
10-
@overload
11-
def fnmatch(name: bytes, pat: bytes) -> bool: pass
12-
13-
@overload
14-
def fnmatchcase(name: str, pat: str) -> bool: pass
15-
@overload
16-
def fnmatchcase(name: bytes, pat: bytes) -> bool: pass
17-
18-
@overload
19-
def filter(names: Iterable[str], pat: str) -> List[str]: pass
20-
@overload
21-
def filter(names: Iterable[bytes], pat: bytes) -> List[bytes]: pass
8+
def fnmatch(name: AnyStr, pat: AnyStr) -> bool: pass
9+
def fnmatchcase(name: AnyStr, pat: AnyStr) -> bool: pass
10+
def filter(names: Iterable[AnyStr], pat: AnyStr) -> List[AnyStr]: pass
2211
def translate(pat: str) -> str: pass

stubs/3.2/glob.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22

33
# Based on http://docs.python.org/3.2/library/glob.html
44

5-
from typing import overload, List, Iterator
5+
from typing import List, Iterator, AnyStr
66

7-
@overload
8-
def glob(pathname: str) -> List[str]: pass
9-
@overload
10-
def glob(pathname: bytes) -> List[bytes]: pass
11-
@overload
12-
def iglob(pathname: str) -> Iterator[str]: pass
13-
@overload
14-
def iglob(pathname: bytes) -> Iterator[bytes]: pass
7+
def glob(pathname: AnyStr) -> List[AnyStr]: pass
8+
def iglob(pathname: AnyStr) -> Iterator[AnyStr]: pass

stubs/3.2/posixpath.py

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

44
# based on http://docs.python.org/3.2/library/os.path.html
55

6-
from typing import Any, List, Tuple, IO, overload
6+
from typing import Any, List, Tuple, IO
77

88
# ----- os.path variables -----
99
supports_unicode_filenames = False

stubs/3.2/re.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# and http://hg.python.org/cpython/file/618ea5612e83/Lib/re.py
77

88
from typing import (
9-
Undefined, List, Iterator, overload, Callable, Tuple, Sequence, Dict,
9+
Undefined, List, Iterator, Callable, Tuple, Sequence, Dict, Union,
1010
Generic, AnyStr, Match, Pattern
1111
)
1212

@@ -46,20 +46,12 @@ def findall(pattern: AnyStr, string: AnyStr,
4646
def finditer(pattern: AnyStr, string: AnyStr,
4747
flags: int = 0) -> Iterator[Match[AnyStr]]: pass
4848

49-
@overload
50-
def sub(pattern: AnyStr, repl: AnyStr, string: AnyStr, count: int = 0,
51-
flags: int = 0) -> AnyStr: pass
52-
@overload
53-
def sub(pattern: AnyStr, repl: Callable[[Match[AnyStr]], AnyStr],
49+
def sub(pattern: AnyStr, repl: Union[AnyStr, Callable[[Match[AnyStr]], AnyStr]],
5450
string: AnyStr, count: int = 0, flags: int = 0) -> AnyStr: pass
5551

56-
@overload
57-
def subn(pattern: AnyStr, repl: AnyStr, string: AnyStr, count: int = 0,
58-
flags: int = 0) -> Tuple[AnyStr, int]: pass
59-
@overload
60-
def subn(pattern: AnyStr, repl: Callable[[Match[AnyStr]], AnyStr],
61-
string: AnyStr, count: int = 0,
62-
flags: int = 0) -> Tuple[AnyStr, int]: pass
52+
def subn(pattern: AnyStr, repl: Union[AnyStr, Callable[[Match[AnyStr]], AnyStr]],
53+
string: AnyStr, count: int = 0, flags: int = 0) -> Tuple[AnyStr, int]:
54+
pass
6355

6456
def escape(string: AnyStr) -> AnyStr: pass
6557

stubs/3.2/shutil.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
# sometimes they only work partially (broken exception messages), and the test
77
# cases don't use them.
88

9-
from typing import (
10-
overload, List, Iterable, Callable, Any, Tuple, Sequence, IO, AnyStr
11-
)
9+
from typing import List, Iterable, Callable, Any, Tuple, Sequence, IO, AnyStr
1210

1311
def copyfileobj(fsrc: IO[AnyStr], fdst: IO[AnyStr],
1412
length: int = None) -> None: pass

stubs/3.2/struct.py

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,26 @@
22

33
# Based on http://docs.python.org/3.2/library/struct.html
44

5-
from typing import overload, Any, Undefined
5+
from typing import overload, Any, Undefined, AnyStr
66

77
class error(Exception): pass
88

9-
@overload
10-
def pack(fmt: str, *v: Any) -> bytes: pass
11-
@overload
12-
def pack(fmt: bytes, *v: Any) -> bytes: pass
13-
14-
@overload
15-
def pack_into(fmt: str, buffer: Any, offset: int, *v: Any) -> None: pass
9+
def pack(fmt: AnyStr, *v: Any) -> bytes: pass
1610
# TODO buffer type
17-
@overload
18-
def pack_into(fmt: bytes, buffer: Any, offset: int, *v: Any) -> None: pass
11+
def pack_into(fmt: AnyStr, buffer: Any, offset: int, *v: Any) -> None: pass
1912

2013
# TODO return type should be tuple
2114
# TODO buffer type
22-
@overload
23-
def unpack(fmt: str, buffer: Any) -> Any: pass
24-
@overload
25-
def unpack(fmt: bytes, buffer: Any) -> Any: pass
26-
27-
@overload
28-
def unpack_from(fmt: str, buffer: Any) -> Any: pass
29-
@overload
30-
def unpack_from(fmt: bytes, buffer: Any, offset: int = 0) -> Any: pass
15+
def unpack(fmt: AnyStr, buffer: Any) -> Any: pass
16+
def unpack_from(fmt: AnyStr, buffer: Any, offset: int = 0) -> Any: pass
3117

32-
@overload
33-
def calcsize(fmt: str) -> int: pass
34-
@overload
35-
def calcsize(fmt: bytes) -> int: pass
18+
def calcsize(fmt: AnyStr) -> int: pass
3619

3720
class Struct:
3821
format = b''
3922
size = 0
4023

41-
@overload
42-
def __init__(self, format: str) -> None: pass
43-
@overload
44-
def __init__(self, format: bytes) -> None: pass
24+
def __init__(self, format: AnyStr) -> None: pass
4525

4626
def pack(self, *v: Any) -> bytes: pass
4727
# TODO buffer type

stubs/3.2/warnings.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,13 @@
22

33
# Based on http://docs.python.org/3.2/library/warnings.html
44

5-
from typing import overload, Any, List, TextIO
5+
from typing import Any, List, TextIO, Union
66

7-
@overload
8-
def warn(message: str, category: type = None,
9-
stacklevel: int = 1) -> None: pass
10-
@overload
11-
def warn(message: Warning, category: type = None,
7+
def warn(message: Union[str, Warning], category: type = None,
128
stacklevel: int = 1) -> None: pass
139

14-
@overload
15-
def warn_explicit(message: str, category: type, filename: str, lineno: int,
16-
module: str = None, registry: Any = None,
17-
module_globals: Any = None) -> None: pass
18-
@overload
19-
def warn_explicit(message: Warning, category: type, filename: str, lineno: int,
20-
module: str = None, registry: Any = None,
10+
def warn_explicit(message: Union[str, Warning], category: type, filename: str,
11+
lineno: int, module: str = None, registry: Any = None,
2112
module_globals: Any = None) -> None: pass
2213

2314
# logging modifies showwarning => make it a variable.

0 commit comments

Comments
 (0)