Skip to content

Commit 24b0bc3

Browse files
authored
Update typing for Python 3.7 (2) (#1556)
1 parent d616f2b commit 24b0bc3

23 files changed

+45
-49
lines changed

astroid/brain/brain_builtin_inference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from __future__ import annotations
88

99
import itertools
10+
from collections.abc import Iterator
1011
from functools import partial
11-
from typing import Iterator
1212

1313
from astroid import arguments, helpers, inference_tip, nodes, objects, util
1414
from astroid.builder import AstroidBuilder

astroid/brain/brain_dataclasses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
from __future__ import annotations
1717

1818
import sys
19-
from typing import Generator, Tuple, Union
19+
from collections.abc import Generator
20+
from typing import Tuple, Union
2021

2122
from astroid import context, inference_tip
2223
from astroid.builder import parse

astroid/brain/brain_functools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
from __future__ import annotations
88

9+
from collections.abc import Iterator
910
from functools import partial
1011
from itertools import chain
11-
from typing import Iterator
1212

1313
from astroid import BoundMethod, arguments, extract_node, helpers, nodes, objects
1414
from astroid.context import InferenceContext

astroid/brain/brain_namedtuple_enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import functools
1010
import keyword
11+
from collections.abc import Iterator
1112
from textwrap import dedent
12-
from typing import Iterator
1313

1414
import astroid
1515
from astroid import arguments, inference_tip, nodes, util

astroid/brain/brain_typing.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from __future__ import annotations
88

99
import typing
10+
from collections.abc import Iterator
1011
from functools import partial
1112

1213
from astroid import context, extract_node, inference_tip
@@ -144,7 +145,7 @@ def _looks_like_typing_subscript(node):
144145

145146
def infer_typing_attr(
146147
node: Subscript, ctx: context.InferenceContext | None = None
147-
) -> typing.Iterator[ClassDef]:
148+
) -> Iterator[ClassDef]:
148149
"""Infer a typing.X[...] subscript"""
149150
try:
150151
value = next(node.value.infer()) # type: ignore[union-attr] # value shouldn't be None for Subscript.
@@ -190,15 +191,15 @@ def _looks_like_typedDict( # pylint: disable=invalid-name
190191

191192
def infer_old_typedDict( # pylint: disable=invalid-name
192193
node: ClassDef, ctx: context.InferenceContext | None = None
193-
) -> typing.Iterator[ClassDef]:
194+
) -> Iterator[ClassDef]:
194195
func_to_add = _extract_single_node("dict")
195196
node.locals["__call__"] = [func_to_add]
196197
return iter([node])
197198

198199

199200
def infer_typedDict( # pylint: disable=invalid-name
200201
node: FunctionDef, ctx: context.InferenceContext | None = None
201-
) -> typing.Iterator[ClassDef]:
202+
) -> Iterator[ClassDef]:
202203
"""Replace TypedDict FunctionDef with ClassDef."""
203204
class_def = ClassDef(
204205
name="TypedDict",
@@ -258,7 +259,7 @@ def full_raiser(origin_func, attr, *args, **kwargs):
258259

259260
def infer_typing_alias(
260261
node: Call, ctx: context.InferenceContext | None = None
261-
) -> typing.Iterator[ClassDef]:
262+
) -> Iterator[ClassDef]:
262263
"""
263264
Infers the call to _alias function
264265
Insert ClassDef, with same name as aliased class,
@@ -346,7 +347,7 @@ def _looks_like_special_alias(node: Call) -> bool:
346347

347348
def infer_special_alias(
348349
node: Call, ctx: context.InferenceContext | None = None
349-
) -> typing.Iterator[ClassDef]:
350+
) -> Iterator[ClassDef]:
350351
"""Infer call to tuple alias as new subscriptable class typing.Tuple."""
351352
if not (
352353
isinstance(node.parent, Assign)
@@ -381,7 +382,7 @@ def _looks_like_typing_cast(node: Call) -> bool:
381382

382383
def infer_typing_cast(
383384
node: Call, ctx: context.InferenceContext | None = None
384-
) -> typing.Iterator[NodeNG]:
385+
) -> Iterator[NodeNG]:
385386
"""Infer call to cast() returning same type as casted-from var"""
386387
if not isinstance(node.func, (Name, Attribute)):
387388
raise UseInferenceDefault

astroid/decorators.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
""" A few useful function/method decorators."""
66

7+
from __future__ import annotations
8+
79
import functools
810
import inspect
911
import sys
1012
import warnings
11-
from typing import Callable, TypeVar
13+
from collections.abc import Callable
14+
from typing import TypeVar
1215

1316
import wrapt
1417

astroid/inference.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import functools
1212
import itertools
1313
import operator
14-
from typing import TYPE_CHECKING, Any, Callable, Generator, Iterable, Iterator, TypeVar
14+
from collections.abc import Callable, Generator, Iterable, Iterator
15+
from typing import TYPE_CHECKING, Any, TypeVar
1516

1617
from astroid import bases, decorators, helpers, nodes, protocols, util
1718
from astroid.context import (

astroid/inference_tip.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from __future__ import annotations
88

99
import typing
10+
from collections.abc import Iterator
1011

1112
import wrapt
1213

@@ -30,7 +31,7 @@ def clear_inference_tip_cache():
3031
@wrapt.decorator
3132
def _inference_tip_cached(
3233
func: InferFn, instance: None, args: typing.Any, kwargs: typing.Any
33-
) -> typing.Iterator[InferOptions]:
34+
) -> Iterator[InferOptions]:
3435
"""Cache decorator used for inference tips"""
3536
node = args[0]
3637
try:

astroid/interpreter/_import/spec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
import os
1313
import sys
1414
import zipimport
15+
from collections.abc import Sequence
1516
from functools import lru_cache
1617
from pathlib import Path
17-
from typing import NamedTuple, Sequence
18+
from typing import NamedTuple
1819

1920
from astroid.modutils import EXT_LIB_DIRS
2021

astroid/nodes/node_classes.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,9 @@
1111
import sys
1212
import typing
1313
import warnings
14+
from collections.abc import Generator, Iterator
1415
from functools import lru_cache
15-
from typing import (
16-
TYPE_CHECKING,
17-
Any,
18-
Callable,
19-
ClassVar,
20-
Generator,
21-
Iterator,
22-
Optional,
23-
TypeVar,
24-
Union,
25-
)
16+
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Optional, TypeVar, Union
2617

2718
from astroid import decorators, mixins, util
2819
from astroid.bases import Instance, _infer_stmts

0 commit comments

Comments
 (0)