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

astroid/nodes/node_ng.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,9 @@
77
import pprint
88
import sys
99
import warnings
10+
from collections.abc import Iterator
1011
from functools import singledispatch as _singledispatch
11-
from typing import (
12-
TYPE_CHECKING,
13-
ClassVar,
14-
Iterator,
15-
Tuple,
16-
Type,
17-
TypeVar,
18-
Union,
19-
cast,
20-
overload,
21-
)
12+
from typing import TYPE_CHECKING, ClassVar, Tuple, Type, TypeVar, Union, cast, overload
2213

2314
from astroid import decorators, util
2415
from astroid.exceptions import (

astroid/nodes/scoped_nodes/scoped_nodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import itertools
1515
import os
1616
import sys
17-
import typing
1817
import warnings
18+
from collections.abc import Iterator
1919
from typing import TYPE_CHECKING, NoReturn, TypeVar, overload
2020

2121
from astroid import bases
@@ -2959,7 +2959,7 @@ def slots(self):
29592959

29602960
def grouped_slots(
29612961
mro: list[ClassDef],
2962-
) -> typing.Iterator[node_classes.NodeNG | None]:
2962+
) -> Iterator[node_classes.NodeNG | None]:
29632963
# Not interested in object, since it can't have slots.
29642964
for cls in mro[:-1]:
29652965
try:

astroid/nodes/scoped_nodes/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from __future__ import annotations
1010

1111
import builtins
12-
from typing import TYPE_CHECKING, Sequence
12+
from collections.abc import Sequence
13+
from typing import TYPE_CHECKING
1314

1415
from astroid.manager import AstroidManager
1516

astroid/objects.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
from __future__ import annotations
1515

1616
import sys
17-
from typing import Iterator, TypeVar
17+
from collections.abc import Iterator
18+
from typing import TypeVar
1819

1920
from astroid import bases, decorators, util
2021
from astroid.context import InferenceContext

astroid/protocols.py

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

1617
from astroid import arguments, bases, decorators, helpers, nodes, util
1718
from astroid.const import Context

astroid/raw_building.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import sys
1515
import types
1616
import warnings
17-
from typing import Iterable
17+
from collections.abc import Iterable
1818

1919
from astroid import bases, nodes
2020
from astroid.manager import AstroidManager

astroid/rebuilder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
import ast
1212
import sys
1313
import token
14+
from collections.abc import Callable, Generator
1415
from io import StringIO
1516
from tokenize import TokenInfo, generate_tokens
16-
from typing import Callable, Generator, TypeVar, Union, cast, overload
17+
from typing import TypeVar, Union, cast, overload
1718

1819
from astroid import nodes
1920
from astroid._ast import ParserModule, get_parser_module, parse_function_type_comment

astroid/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import functools
1111
import sys
1212
import warnings
13-
from typing import Callable
13+
from collections.abc import Callable
1414

1515
import pytest
1616

pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ unsafe-load-any-extension=no
4040
extension-pkg-whitelist=
4141

4242
# Minimum supported python version
43-
py-version = 3.6.2
43+
py-version = 3.7.2
4444

4545

4646
[REPORTS]

tests/unittest_inference.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
import textwrap
1010
import unittest
1111
from abc import ABCMeta
12+
from collections.abc import Callable
1213
from functools import partial
1314
from pathlib import Path
14-
from typing import Any, Callable
15+
from typing import Any
1516
from unittest.mock import patch
1617

1718
import pytest

tests/unittest_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import sys
88
import time
99
import unittest
10+
from collections.abc import Iterator
1011
from contextlib import contextmanager
11-
from typing import Iterator
1212

1313
import pkg_resources
1414

tests/unittest_protocols.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
import contextlib
88
import unittest
9-
from typing import Any, Callable, Iterator
9+
from collections.abc import Callable, Iterator
10+
from typing import Any
1011

1112
import pytest
1213

tests/unittest_transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import contextlib
88
import time
99
import unittest
10-
from typing import Callable, Iterator
10+
from collections.abc import Callable, Iterator
1111

1212
from astroid import MANAGER, builder, nodes, parse, transforms
1313
from astroid.manager import AstroidManager

0 commit comments

Comments
 (0)