Skip to content

Commit

Permalink
Update deprecated type aliases (#4486)
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksMat authored Oct 23, 2024
1 parent f54f347 commit c98fc0c
Show file tree
Hide file tree
Showing 28 changed files with 61 additions and 62 deletions.
3 changes: 2 additions & 1 deletion gallery/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import venv
import zipfile
from argparse import ArgumentParser, Namespace
from collections.abc import Generator
from concurrent.futures import ThreadPoolExecutor
from functools import lru_cache, partial
from pathlib import Path
from typing import Generator, NamedTuple, Optional, Union, cast
from typing import NamedTuple, Optional, Union, cast
from urllib.request import urlopen, urlretrieve

PYPI_INSTANCE = "https://pypi.org/pypi"
Expand Down
2 changes: 1 addition & 1 deletion scripts/make_width_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"""

import sys
from collections.abc import Iterable
from os.path import basename, dirname, join
from typing import Iterable

import wcwidth # type: ignore[import-not-found]

Expand Down
20 changes: 9 additions & 11 deletions src/black/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@
import sys
import tokenize
import traceback
from contextlib import contextmanager
from dataclasses import replace
from datetime import datetime, timezone
from enum import Enum
from json.decoder import JSONDecodeError
from pathlib import Path
from typing import (
Any,
from collections.abc import (
Collection,
Generator,
Iterator,
MutableMapping,
Optional,
Pattern,
Sequence,
Sized,
Union,
)
from contextlib import contextmanager
from dataclasses import replace
from datetime import datetime, timezone
from enum import Enum
from json.decoder import JSONDecodeError
from pathlib import Path
from re import Pattern
from typing import Any, Optional, Union

import click
from click.core import ParameterSource
Expand Down
3 changes: 2 additions & 1 deletion src/black/brackets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Builds on top of nodes.py to track brackets."""

from collections.abc import Iterable, Sequence
from dataclasses import dataclass, field
from typing import Final, Iterable, Optional, Sequence, Union
from typing import Final, Optional, Union

from black.nodes import (
BRACKET,
Expand Down
3 changes: 2 additions & 1 deletion src/black/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import pickle
import sys
import tempfile
from collections.abc import Iterable
from dataclasses import dataclass, field
from pathlib import Path
from typing import Iterable, NamedTuple
from typing import NamedTuple

from platformdirs import user_cache_dir

Expand Down
3 changes: 2 additions & 1 deletion src/black/comments.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import re
from collections.abc import Collection, Iterator
from dataclasses import dataclass
from functools import lru_cache
from typing import Collection, Final, Iterator, Optional, Union
from typing import Final, Optional, Union

from black.mode import Mode, Preview
from black.nodes import (
Expand Down
3 changes: 2 additions & 1 deletion src/black/concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import signal
import sys
import traceback
from collections.abc import Iterable
from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor
from multiprocessing import Manager
from pathlib import Path
from typing import Any, Iterable, Optional
from typing import Any, Optional

from mypy_extensions import mypyc_attr

Expand Down
3 changes: 2 additions & 1 deletion src/black/debug.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Iterator
from dataclasses import dataclass, field
from typing import Any, Iterator, TypeVar, Union
from typing import Any, TypeVar, Union

from black.nodes import Visitor
from black.output import out
Expand Down
13 changes: 3 additions & 10 deletions src/black/files.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import io
import os
import sys
from collections.abc import Iterable, Iterator, Sequence
from functools import lru_cache
from pathlib import Path
from typing import (
TYPE_CHECKING,
Any,
Iterable,
Iterator,
Optional,
Pattern,
Sequence,
Union,
)
from re import Pattern
from typing import TYPE_CHECKING, Any, Optional, Union

from mypy_extensions import mypyc_attr
from packaging.specifiers import InvalidSpecifier, Specifier, SpecifierSet
Expand Down
3 changes: 2 additions & 1 deletion src/black/linegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import re
import sys
from collections.abc import Collection, Iterator
from dataclasses import replace
from enum import Enum, auto
from functools import partial, wraps
from typing import Collection, Iterator, Optional, Union, cast
from typing import Optional, Union, cast

from black.brackets import (
COMMA_PRIORITY,
Expand Down
3 changes: 2 additions & 1 deletion src/black/lines.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import itertools
import math
from collections.abc import Callable, Iterator, Sequence
from dataclasses import dataclass, field
from typing import Callable, Iterator, Optional, Sequence, TypeVar, Union, cast
from typing import Optional, TypeVar, Union, cast

from black.brackets import COMMA_PRIORITY, DOT_PRIORITY, BracketTracker
from black.mode import Mode, Preview
Expand Down
3 changes: 2 additions & 1 deletion src/black/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"""

import sys
from typing import Final, Generic, Iterator, Literal, Optional, TypeVar, Union
from collections.abc import Iterator
from typing import Final, Generic, Literal, Optional, TypeVar, Union

if sys.version_info >= (3, 10):
from typing import TypeGuard
Expand Down
2 changes: 1 addition & 1 deletion src/black/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ast
import sys
import warnings
from typing import Collection, Iterator
from collections.abc import Collection, Iterator

from black.mode import VERSION_TO_FEATURES, Feature, TargetVersion, supports_feature
from black.nodes import syms
Expand Down
3 changes: 2 additions & 1 deletion src/black/ranges.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Functions related to Black's formatting by line ranges feature."""

import difflib
from collections.abc import Collection, Iterator, Sequence
from dataclasses import dataclass
from typing import Collection, Iterator, Sequence, Union
from typing import Union

from black.nodes import (
LN,
Expand Down
3 changes: 2 additions & 1 deletion src/black/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import re
import sys
from functools import lru_cache
from typing import Final, Match, Pattern
from re import Match, Pattern
from typing import Final

from black._width_table import WIDTH_TABLE
from blib2to3.pytree import Leaf
Expand Down
16 changes: 2 additions & 14 deletions src/black/trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,9 @@
import re
from abc import ABC, abstractmethod
from collections import defaultdict
from collections.abc import Callable, Collection, Iterable, Iterator, Sequence
from dataclasses import dataclass
from typing import (
Any,
Callable,
ClassVar,
Collection,
Final,
Iterable,
Iterator,
Literal,
Optional,
Sequence,
TypeVar,
Union,
)
from typing import Any, ClassVar, Final, Literal, Optional, TypeVar, Union

from mypy_extensions import trait

Expand Down
2 changes: 1 addition & 1 deletion src/blackd/middlewares.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Awaitable, Callable, Iterable
from collections.abc import Awaitable, Callable, Iterable

from aiohttp.typedefs import Middleware
from aiohttp.web_middlewares import middleware
Expand Down
3 changes: 2 additions & 1 deletion src/blib2to3/pgen2/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
import os
import pkgutil
import sys
from collections.abc import Iterable, Iterator
from contextlib import contextmanager
from dataclasses import dataclass, field
from logging import Logger
from typing import IO, Any, Iterable, Iterator, Optional, Union, cast
from typing import IO, Any, Optional, Union, cast

from blib2to3.pgen2.grammar import Grammar
from blib2to3.pgen2.tokenize import GoodTokenInfo
Expand Down
3 changes: 1 addition & 2 deletions src/blib2to3/pgen2/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""Safely evaluate Python string literals without using eval()."""

import re
from typing import Match

simple_escapes: dict[str, str] = {
"a": "\a",
Expand All @@ -20,7 +19,7 @@
}


def escape(m: Match[str]) -> str:
def escape(m: re.Match[str]) -> str:
all, tail = m.group(0, 1)
assert all.startswith("\\")
esc = simple_escapes.get(tail)
Expand Down
3 changes: 2 additions & 1 deletion src/blib2to3/pgen2/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
how this parsing engine works.
"""
from collections.abc import Callable, Iterator
from contextlib import contextmanager
from typing import TYPE_CHECKING, Any, Callable, Iterator, Optional, Union, cast
from typing import TYPE_CHECKING, Any, Optional, Union, cast

from blib2to3.pgen2.grammar import Grammar
from blib2to3.pytree import NL, Context, Leaf, Node, RawNode, convert
Expand Down
3 changes: 2 additions & 1 deletion src/blib2to3/pgen2/pgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Licensed to PSF under a Contributor Agreement.

import os
from typing import IO, Any, Iterator, NoReturn, Optional, Sequence, Union
from collections.abc import Iterator, Sequence
from typing import IO, Any, NoReturn, Optional, Union

from blib2to3.pgen2 import grammar, token, tokenize
from blib2to3.pgen2.tokenize import GoodTokenInfo
Expand Down
4 changes: 3 additions & 1 deletion src/blib2to3/pgen2/tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@

import builtins
import sys
from typing import Callable, Final, Iterable, Iterator, Optional, Pattern, Union
from collections.abc import Callable, Iterable, Iterator
from re import Pattern
from typing import Final, Optional, Union

from blib2to3.pgen2.grammar import Grammar
from blib2to3.pgen2.token import (
Expand Down
3 changes: 2 additions & 1 deletion src/blib2to3/pytree.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

# mypy: allow-untyped-defs, allow-incomplete-defs

from typing import Any, Iterable, Iterator, Optional, TypeVar, Union
from collections.abc import Iterable, Iterator
from typing import Any, Optional, TypeVar, Union

from blib2to3.pgen2.grammar import Grammar

Expand Down
3 changes: 2 additions & 1 deletion tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import sys
import textwrap
import types
from collections.abc import Callable, Iterator, Sequence
from concurrent.futures import ThreadPoolExecutor
from contextlib import contextmanager, redirect_stderr
from dataclasses import fields, replace
from io import BytesIO
from pathlib import Path, WindowsPath
from platform import system
from tempfile import TemporaryDirectory
from typing import Any, Callable, Iterator, Optional, Sequence, TypeVar, Union
from typing import Any, Optional, TypeVar, Union
from unittest.mock import MagicMock, patch

import click
Expand Down
3 changes: 2 additions & 1 deletion tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"""

import re
from collections.abc import Sequence
from itertools import islice
from pathlib import Path
from typing import Optional, Sequence
from typing import Optional

import pytest

Expand Down
3 changes: 2 additions & 1 deletion tests/test_format.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Iterator
from dataclasses import replace
from typing import Any, Iterator
from typing import Any
from unittest.mock import patch

import pytest
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ipynb.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import contextlib
import pathlib
import re
from contextlib import AbstractContextManager
from contextlib import ExitStack as does_not_raise
from dataclasses import replace
from typing import ContextManager

import pytest
from _pytest.monkeypatch import MonkeyPatch
Expand Down Expand Up @@ -213,7 +213,7 @@ def test_cell_magic_with_empty_lines(src: str, expected: str) -> None:
],
)
def test_cell_magic_with_custom_python_magic(
mode: Mode, expected_output: str, expectation: ContextManager[object]
mode: Mode, expected_output: str, expectation: AbstractContextManager[object]
) -> None:
with expectation:
result = format_cell(
Expand Down
3 changes: 2 additions & 1 deletion tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import shlex
import sys
import unittest
from collections.abc import Collection, Iterator
from contextlib import contextmanager
from dataclasses import dataclass, field, replace
from functools import partial
from pathlib import Path
from typing import Any, Collection, Iterator, Optional
from typing import Any, Optional

import black
from black.const import DEFAULT_LINE_LENGTH
Expand Down

0 comments on commit c98fc0c

Please sign in to comment.