Skip to content

Use short type var names #2974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/2/__builtin__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ Ellipsis: ellipsis

if sys.version_info < (3,):
# TODO: buffer support is incomplete; e.g. some_string.startswith(some_buffer) doesn't type check.
_AnyBuffer = TypeVar('_AnyBuffer', str, unicode, bytearray, buffer)
_AnyBuffer = Union[str, unicode, bytearray, buffer]

class buffer(Sized):
def __init__(self, object: _AnyBuffer, offset: int = ..., size: int = ...) -> None: ...
Expand Down
12 changes: 6 additions & 6 deletions stdlib/2/collections.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class deque(Sized, Iterable[_T], Reversible[_T], Generic[_T]):
def __reversed__(self) -> Iterator[_T]: ...
def __iadd__(self: _S, iterable: Iterable[_T]) -> _S: ...

_CounterT = TypeVar('_CounterT', bound=Counter)
_CT = TypeVar('_CT', bound=Counter)

class Counter(Dict[_T, int], Generic[_T]):
@overload
Expand All @@ -65,7 +65,7 @@ class Counter(Dict[_T, int], Generic[_T]):
def __init__(self, mapping: Mapping[_T, int]) -> None: ...
@overload
def __init__(self, iterable: Iterable[_T]) -> None: ...
def copy(self: _CounterT) -> _CounterT: ...
def copy(self: _CT) -> _CT: ...
def elements(self) -> Iterator[_T]: ...
def most_common(self, n: Optional[int] = ...) -> List[Tuple[_T, int]]: ...
@overload
Expand Down Expand Up @@ -93,14 +93,14 @@ class Counter(Dict[_T, int], Generic[_T]):
def __iand__(self, other: Counter[_T]) -> Counter[_T]: ...
def __ior__(self, other: Counter[_T]) -> Counter[_T]: ...

_OrderedDictT = TypeVar('_OrderedDictT', bound=OrderedDict)
_ODT = TypeVar('_ODT', bound=OrderedDict)

class OrderedDict(Dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
def popitem(self, last: bool = ...) -> Tuple[_KT, _VT]: ...
def copy(self: _OrderedDictT) -> _OrderedDictT: ...
def copy(self: _ODT) -> _ODT: ...
def __reversed__(self) -> Iterator[_KT]: ...

_DefaultDictT = TypeVar('_DefaultDictT', bound=defaultdict)
_DDT = TypeVar('_DDT', bound=defaultdict)

class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]):
default_factory: Callable[[], _VT]
Expand All @@ -123,4 +123,4 @@ class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]):
def __init__(self, default_factory: Optional[Callable[[], _VT]],
iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
def __missing__(self, key: _KT) -> _VT: ...
def copy(self: _DefaultDictT) -> _DefaultDictT: ...
def copy(self: _DDT) -> _DDT: ...
4 changes: 2 additions & 2 deletions stdlib/2/mutex.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from collections import deque
from typing import Any, Callable, TypeVar

_ArgType = TypeVar('_ArgType')
_T = TypeVar('_T')

class mutex:
locked: bool
queue: deque
def __init__(self) -> None: ...
def test(self) -> bool: ...
def testandset(self) -> bool: ...
def lock(self, function: Callable[[_ArgType], Any], argument: _ArgType) -> None: ...
def lock(self, function: Callable[[_T], Any], argument: _T) -> None: ...
def unlock(self) -> None: ...
24 changes: 12 additions & 12 deletions stdlib/2/sets.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from typing import Any, Callable, Hashable, Iterable, Iterator, MutableMapping,

_T = TypeVar('_T')
_Setlike = Union[BaseSet[_T], Iterable[_T]]
_SelfT = TypeVar('_SelfT', bound=BaseSet)
_S = TypeVar('_S', bound=BaseSet)

class BaseSet(Iterable[_T]):
def __init__(self) -> None: ...
Expand All @@ -14,17 +14,17 @@ class BaseSet(Iterable[_T]):
def __cmp__(self, other: Any) -> int: ...
def __eq__(self, other: Any) -> bool: ...
def __ne__(self, other: Any) -> bool: ...
def copy(self: _SelfT) -> _SelfT: ...
def __copy__(self: _SelfT) -> _SelfT: ...
def __deepcopy__(self: _SelfT, memo: MutableMapping[int, BaseSet[_T]]) -> _SelfT: ...
def __or__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ...
def union(self: _SelfT, other: _Setlike) -> _SelfT: ...
def __and__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ...
def intersection(self: _SelfT, other: _Setlike) -> _SelfT: ...
def __xor__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ...
def symmetric_difference(self: _SelfT, other: _Setlike) -> _SelfT: ...
def __sub__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ...
def difference(self: _SelfT, other: _Setlike) -> _SelfT: ...
def copy(self: _S) -> _S: ...
def __copy__(self: _S) -> _S: ...
def __deepcopy__(self: _S, memo: MutableMapping[int, BaseSet[_T]]) -> _S: ...
def __or__(self: _S, other: BaseSet[_T]) -> _S: ...
def union(self: _S, other: _Setlike) -> _S: ...
def __and__(self: _S, other: BaseSet[_T]) -> _S: ...
def intersection(self: _S, other: _Setlike) -> _S: ...
def __xor__(self: _S, other: BaseSet[_T]) -> _S: ...
def symmetric_difference(self: _S, other: _Setlike) -> _S: ...
def __sub__(self: _S, other: BaseSet[_T]) -> _S: ...
def difference(self: _S, other: _Setlike) -> _S: ...
def __contains__(self, element: Any) -> bool: ...
def issubset(self, other: BaseSet[_T]) -> bool: ...
def issuperset(self, other: BaseSet[_T]) -> bool: ...
Expand Down
34 changes: 17 additions & 17 deletions stdlib/2/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -403,39 +403,39 @@ class Match(Generic[AnyStr]):
# Pattern is generic over AnyStr (determining the type of its .pattern
# attribute), but at the same time its methods take either bytes or
# Text and return the same type, regardless of the type of the pattern.
_AnyStr2 = TypeVar('_AnyStr2', bytes, Text)
_AS = TypeVar('_AS', bytes, Text)

class Pattern(Generic[AnyStr]):
flags: int
groupindex: Dict[AnyStr, int]
groups: int
pattern: AnyStr

def search(self, string: _AnyStr2, pos: int = ...,
endpos: int = ...) -> Optional[Match[_AnyStr2]]: ...
def match(self, string: _AnyStr2, pos: int = ...,
endpos: int = ...) -> Optional[Match[_AnyStr2]]: ...
def split(self, string: _AnyStr2, maxsplit: int = ...) -> List[_AnyStr2]: ...
# Returns either a list of _AnyStr2 or a list of tuples, depending on
def search(self, string: _AS, pos: int = ...,
endpos: int = ...) -> Optional[Match[_AS]]: ...
def match(self, string: _AS, pos: int = ...,
endpos: int = ...) -> Optional[Match[_AS]]: ...
def split(self, string: _AS, maxsplit: int = ...) -> List[_AS]: ...
# Returns either a list of _AS or a list of tuples, depending on
# whether there are groups in the pattern.
def findall(self, string: Union[bytes, Text], pos: int = ...,
endpos: int = ...) -> List[Any]: ...
def finditer(self, string: _AnyStr2, pos: int = ...,
endpos: int = ...) -> Iterator[Match[_AnyStr2]]: ...
def finditer(self, string: _AS, pos: int = ...,
endpos: int = ...) -> Iterator[Match[_AS]]: ...

@overload
def sub(self, repl: _AnyStr2, string: _AnyStr2,
count: int = ...) -> _AnyStr2: ...
def sub(self, repl: _AS, string: _AS,
count: int = ...) -> _AS: ...
@overload
def sub(self, repl: Callable[[Match[_AnyStr2]], _AnyStr2], string: _AnyStr2,
count: int = ...) -> _AnyStr2: ...
def sub(self, repl: Callable[[Match[_AS]], _AS], string: _AS,
count: int = ...) -> _AS: ...

@overload
def subn(self, repl: _AnyStr2, string: _AnyStr2,
count: int = ...) -> Tuple[_AnyStr2, int]: ...
def subn(self, repl: _AS, string: _AS,
count: int = ...) -> Tuple[_AS, int]: ...
@overload
def subn(self, repl: Callable[[Match[_AnyStr2]], _AnyStr2], string: _AnyStr2,
count: int = ...) -> Tuple[_AnyStr2, int]: ...
def subn(self, repl: Callable[[Match[_AS]], _AS], string: _AS,
count: int = ...) -> Tuple[_AS, int]: ...

# Functions

Expand Down
18 changes: 9 additions & 9 deletions stdlib/2and3/_weakrefset.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ from typing import Iterator, Any, Iterable, MutableSet, Optional, TypeVar, Gener

_S = TypeVar('_S')
_T = TypeVar('_T')
_SelfT = TypeVar('_SelfT', bound=WeakSet)
_WS = TypeVar('_WS', bound=WeakSet)

class WeakSet(MutableSet[_T], Generic[_T]):
def __init__(self, data: Optional[Iterable[_T]] = ...) -> None: ...

def add(self, item: _T) -> None: ...
def clear(self) -> None: ...
def discard(self, item: _T) -> None: ...
def copy(self: _SelfT) -> _SelfT: ...
def copy(self: _WS) -> _WS: ...
def pop(self) -> _T: ...
def remove(self, item: _T) -> None: ...
def update(self, other: Iterable[_T]) -> None: ...
Expand All @@ -19,14 +19,14 @@ class WeakSet(MutableSet[_T], Generic[_T]):
def __iter__(self) -> Iterator[_T]: ...

def __ior__(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ...
def difference(self: _SelfT, other: Iterable[_T]) -> _SelfT: ...
def __sub__(self: _SelfT, other: Iterable[_T]) -> _SelfT: ...
def difference_update(self: _SelfT, other: Iterable[_T]) -> None: ...
def __isub__(self: _SelfT, other: Iterable[_T]) -> _SelfT: ...
def intersection(self: _SelfT, other: Iterable[_T]) -> _SelfT: ...
def __and__(self: _SelfT, other: Iterable[_T]) -> _SelfT: ...
def difference(self: _WS, other: Iterable[_T]) -> _WS: ...
def __sub__(self: _WS, other: Iterable[_T]) -> _WS: ...
def difference_update(self: _WS, other: Iterable[_T]) -> None: ...
def __isub__(self: _WS, other: Iterable[_T]) -> _WS: ...
def intersection(self: _WS, other: Iterable[_T]) -> _WS: ...
def __and__(self: _WS, other: Iterable[_T]) -> _WS: ...
def intersection_update(self, other: Iterable[_T]) -> None: ...
def __iand__(self: _SelfT, other: Iterable[_T]) -> _SelfT: ...
def __iand__(self: _WS, other: Iterable[_T]) -> _WS: ...
def issubset(self, other: Iterable[_T]) -> bool: ...
def __le__(self, other: Iterable[_T]) -> bool: ...
def __lt__(self, other: Iterable[_T]) -> bool: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/2and3/argparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from typing import (
import sys

_T = TypeVar('_T')
_ActionT = TypeVar('_ActionT', bound='Action')
_A = TypeVar('_A', bound='Action')
_N = TypeVar('_N')

if sys.version_info >= (3,):
Expand Down Expand Up @@ -68,7 +68,7 @@ class _ActionsContainer:
**kwargs: Any) -> Action: ...
def add_argument_group(self, *args: Any, **kwargs: Any) -> _ArgumentGroup: ...
def add_mutually_exclusive_group(self, **kwargs: Any) -> _MutuallyExclusiveGroup: ...
def _add_action(self, action: _ActionT) -> _ActionT: ...
def _add_action(self, action: _A) -> _A: ...
def _remove_action(self, action: Action) -> None: ...
def _add_container_actions(self, container: _ActionsContainer) -> None: ...
def _get_positional_kwargs(self, dest: _Text, **kwargs: Any) -> Dict[str, Any]: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/2and3/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ Ellipsis: ellipsis

if sys.version_info < (3,):
# TODO: buffer support is incomplete; e.g. some_string.startswith(some_buffer) doesn't type check.
_AnyBuffer = TypeVar('_AnyBuffer', str, unicode, bytearray, buffer)
_AnyBuffer = Union[str, unicode, bytearray, buffer]

class buffer(Sized):
def __init__(self, object: _AnyBuffer, offset: int = ..., size: int = ...) -> None: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/2and3/cProfile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from typing import Any, Callable, Dict, Optional, Text, TypeVar, Union
def run(statement: str, filename: Optional[str] = ..., sort: Union[str, int] = ...) -> None: ...
def runctx(statement: str, globals: Dict[str, Any], locals: Dict[str, Any], filename: Optional[str] = ..., sort: Union[str, int] = ...) -> None: ...

_SelfT = TypeVar('_SelfT', bound='Profile')
_S = TypeVar('_S', bound='Profile')
_T = TypeVar('_T')
if sys.version_info >= (3, 6):
_Path = Union[bytes, Text, os.PathLike[Any]]
Expand All @@ -19,6 +19,6 @@ class Profile:
def print_stats(self, sort: Union[str, int] = ...) -> None: ...
def dump_stats(self, file: _Path) -> None: ...
def create_stats(self) -> None: ...
def run(self: _SelfT, cmd: str) -> _SelfT: ...
def runctx(self: _SelfT, cmd: str, globals: Dict[str, Any], locals: Dict[str, Any]) -> _SelfT: ...
def run(self: _S, cmd: str) -> _S: ...
def runctx(self: _S, cmd: str, globals: Dict[str, Any], locals: Dict[str, Any]) -> _S: ...
def runcall(self, func: Callable[..., _T], *args: Any, **kw: Any) -> _T: ...
4 changes: 2 additions & 2 deletions stdlib/2and3/decimal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if sys.version_info >= (3,):
_ComparableNum = Union[Decimal, float, numbers.Rational]
else:
_ComparableNum = Union[Decimal, float]
_DecimalT = TypeVar('_DecimalT', bound=Decimal)
_D = TypeVar('_D', bound=Decimal)

DecimalTuple = NamedTuple('DecimalTuple',
[('sign', int),
Expand Down Expand Up @@ -69,7 +69,7 @@ def getcontext() -> Context: ...
def localcontext(ctx: Optional[Context] = ...) -> _ContextManager: ...

class Decimal(object):
def __new__(cls: Type[_DecimalT], value: _DecimalNew = ..., context: Optional[Context] = ...) -> _DecimalT: ...
def __new__(cls: Type[_D], value: _DecimalNew = ..., context: Optional[Context] = ...) -> _D: ...
@classmethod
def from_float(cls, f: float) -> Decimal: ...
if sys.version_info >= (3,):
Expand Down
40 changes: 20 additions & 20 deletions stdlib/2and3/difflib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ from typing import (
_T = TypeVar('_T')

if sys.version_info >= (3,):
_StrType = Text
_S = Text
else:
# Aliases can't point to type vars, so we need to redeclare AnyStr
_StrType = TypeVar('_StrType', Text, bytes)
_S = TypeVar('_S', Text, bytes)

_JunkCallback = Union[Callable[[Text], bool], Callable[[str], bool]]

Expand Down Expand Up @@ -44,34 +44,34 @@ def get_close_matches(word: Sequence[_T], possibilities: Iterable[Sequence[_T]],

class Differ:
def __init__(self, linejunk: _JunkCallback = ..., charjunk: _JunkCallback = ...) -> None: ...
def compare(self, a: Sequence[_StrType], b: Sequence[_StrType]) -> Iterator[_StrType]: ...
def compare(self, a: Sequence[_S], b: Sequence[_S]) -> Iterator[_S]: ...

def IS_LINE_JUNK(line: _StrType) -> bool: ...
def IS_CHARACTER_JUNK(line: _StrType) -> bool: ...
def unified_diff(a: Sequence[_StrType], b: Sequence[_StrType], fromfile: _StrType = ...,
tofile: _StrType = ..., fromfiledate: _StrType = ..., tofiledate: _StrType = ...,
n: int = ..., lineterm: _StrType = ...) -> Iterator[_StrType]: ...
def context_diff(a: Sequence[_StrType], b: Sequence[_StrType], fromfile: _StrType = ...,
tofile: _StrType = ..., fromfiledate: _StrType = ..., tofiledate: _StrType = ...,
n: int = ..., lineterm: _StrType = ...) -> Iterator[_StrType]: ...
def ndiff(a: Sequence[_StrType], b: Sequence[_StrType],
def IS_LINE_JUNK(line: _S) -> bool: ...
def IS_CHARACTER_JUNK(line: _S) -> bool: ...
def unified_diff(a: Sequence[_S], b: Sequence[_S], fromfile: _S = ...,
tofile: _S = ..., fromfiledate: _S = ..., tofiledate: _S = ...,
n: int = ..., lineterm: _S = ...) -> Iterator[_S]: ...
def context_diff(a: Sequence[_S], b: Sequence[_S], fromfile: _S = ...,
tofile: _S = ..., fromfiledate: _S = ..., tofiledate: _S = ...,
n: int = ..., lineterm: _S = ...) -> Iterator[_S]: ...
def ndiff(a: Sequence[_S], b: Sequence[_S],
linejunk: _JunkCallback = ...,
charjunk: _JunkCallback = ...
) -> Iterator[_StrType]: ...
) -> Iterator[_S]: ...

class HtmlDiff(object):
def __init__(self, tabsize: int = ..., wrapcolumn: int = ...,
linejunk: _JunkCallback = ...,
charjunk: _JunkCallback = ...
) -> None: ...
def make_file(self, fromlines: Sequence[_StrType], tolines: Sequence[_StrType],
fromdesc: _StrType = ..., todesc: _StrType = ..., context: bool = ...,
numlines: int = ...) -> _StrType: ...
def make_table(self, fromlines: Sequence[_StrType], tolines: Sequence[_StrType],
fromdesc: _StrType = ..., todesc: _StrType = ..., context: bool = ...,
numlines: int = ...) -> _StrType: ...
def make_file(self, fromlines: Sequence[_S], tolines: Sequence[_S],
fromdesc: _S = ..., todesc: _S = ..., context: bool = ...,
numlines: int = ...) -> _S: ...
def make_table(self, fromlines: Sequence[_S], tolines: Sequence[_S],
fromdesc: _S = ..., todesc: _S = ..., context: bool = ...,
numlines: int = ...) -> _S: ...

def restore(delta: Iterable[_StrType], which: int) -> Iterator[_StrType]: ...
def restore(delta: Iterable[_S], which: int) -> Iterator[_S]: ...

if sys.version_info >= (3, 5):
def diff_bytes(
Expand Down
6 changes: 3 additions & 3 deletions stdlib/2and3/profile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from typing import Any, Callable, Dict, Optional, Text, TypeVar, Union
def run(statement: str, filename: Optional[str] = ..., sort: Union[str, int] = ...) -> None: ...
def runctx(statement: str, globals: Dict[str, Any], locals: Dict[str, Any], filename: Optional[str] = ..., sort: Union[str, int] = ...) -> None: ...

_SelfT = TypeVar('_SelfT', bound='Profile')
_S = TypeVar('_S', bound='Profile')
_T = TypeVar('_T')
if sys.version_info >= (3, 6):
_Path = Union[bytes, Text, os.PathLike[Any]]
Expand All @@ -21,7 +21,7 @@ class Profile:
def dump_stats(self, file: _Path) -> None: ...
def create_stats(self) -> None: ...
def snapshot_stats(self) -> None: ...
def run(self: _SelfT, cmd: str) -> _SelfT: ...
def runctx(self: _SelfT, cmd: str, globals: Dict[str, Any], locals: Dict[str, Any]) -> _SelfT: ...
def run(self: _S, cmd: str) -> _S: ...
def runctx(self: _S, cmd: str, globals: Dict[str, Any], locals: Dict[str, Any]) -> _S: ...
def runcall(self, func: Callable[..., _T], *args: Any, **kw: Any) -> _T: ...
def calibrate(self, m: int, verbose: int = ...) -> float: ...
Loading