pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/graphql-python/graphql-core/commit/9e16a0b1f27fa367089b39a2db9b3ce7f46c35fa

Remove special casing for older Python versions · graphql-python/graphql-core@9e16a0b · GitHub
Skip to content

Commit 9e16a0b

Browse files
committed
Remove special casing for older Python versions
1 parent e3a37ff commit 9e16a0b

51 files changed

Lines changed: 86 additions & 407 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pyproject.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ test = [
4040
]
4141
lint = [
4242
"ruff>=0.14,<0.15",
43-
"mypy>=1.10,<2",
43+
"mypy>=1.19,<2",
4444
"bump2version>=1,<2",
45+
"typing-extensions>=4.7; python_version<'3.11'",
4546
]
4647
doc = [
47-
"sphinx>=9,<10",
48+
"sphinx>=9.1,<10",
4849
"sphinx_rtd_theme>=3.1.0rc2,<4",
4950
]
5051

@@ -73,7 +74,7 @@ source-exclude = [
7374

7475
[tool.ruff]
7576
line-length = 88
76-
target-version = "py37"
77+
target-version = "py310"
7778

7879
[tool.ruff.lint]
7980
select = [
@@ -118,7 +119,8 @@ select = [
118119
"TCH", # flake8-type-checking
119120
"TID", # flake8-tidy-imports
120121
"TRY", # tryceratops
121-
"UP", # pyupgrade
122+
# TODO: enable again after upgradesc
123+
#"UP", # pyupgrade
122124
"W", # pycodestyle
123125
"YTT", # flake8-2020
124126
]

src/graphql/error/graphql_error.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,7 @@
33
from __future__ import annotations
44

55
from sys import exc_info
6-
from typing import TYPE_CHECKING, Any, Collection, Dict
7-
8-
try:
9-
from typing import TypedDict
10-
except ImportError: # Python < 3.8
11-
from typing_extensions import TypedDict
12-
try:
13-
from typing import TypeAlias
14-
except ImportError: # Python < 3.10
15-
from typing_extensions import TypeAlias
6+
from typing import TYPE_CHECKING, Any, Collection, Dict, TypeAlias, TypedDict
167

178
if TYPE_CHECKING:
189
from ..language.ast import Node

src/graphql/execution/build_field_plan.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22

33
from __future__ import annotations
44

5-
from typing import NamedTuple
5+
from typing import NamedTuple, TypeAlias
66

77
from ..pyutils import RefMap, RefSet
88
from .collect_fields import DeferUsage, FieldGroup, GroupedFieldSet
99

10-
try:
11-
from typing import TypeAlias
12-
except ImportError: # Python < 3.10
13-
from typing_extensions import TypeAlias
14-
1510
__all__ = [
1611
"DeferUsageSet",
1712
"FieldPlan",

src/graphql/execution/collect_fields.py

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

33
from __future__ import annotations
44

5-
import sys
65
from collections import defaultdict
7-
from typing import Any, NamedTuple
6+
from typing import Any, NamedTuple, TypeAlias
87

98
from ..language import (
109
FieldNode,
@@ -26,11 +25,6 @@
2625
from ..utilities.type_from_ast import type_from_ast
2726
from .values import get_directive_values
2827

29-
try:
30-
from typing import TypeAlias
31-
except ImportError: # Python < 3.10
32-
from typing_extensions import TypeAlias
33-
3428
__all__ = [
3529
"CollectFieldsContext",
3630
"CollectedFields",
@@ -67,14 +61,8 @@ class FieldDetails(NamedTuple):
6761
defer_usage: DeferUsage | None
6862

6963

70-
if sys.version_info < (3, 9):
71-
from typing import Dict, List
72-
73-
FieldGroup: TypeAlias = List[FieldDetails]
74-
GroupedFieldSet: TypeAlias = Dict[str, FieldGroup]
75-
else: # Python >= 3.9
76-
FieldGroup: TypeAlias = list[FieldDetails]
77-
GroupedFieldSet: TypeAlias = dict[str, FieldGroup]
64+
FieldGroup: TypeAlias = list[FieldDetails]
65+
GroupedFieldSet: TypeAlias = dict[str, FieldGroup]
7866

7967

8068
class CollectFieldsContext(NamedTuple):

src/graphql/execution/execute.py

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
from asyncio import (
6-
CancelledError,
76
TimeoutError, # only needed for Python < 3.11 # noqa: A004
87
ensure_future,
98
sleep,
@@ -108,21 +107,9 @@
108107
from .values import get_argument_values, get_directive_values, get_variable_values
109108

110109
if TYPE_CHECKING:
111-
from ..pyutils import UndefinedType
112-
113-
try:
114-
from typing import TypeAlias, TypeGuard
115-
except ImportError: # Python < 3.10
116-
from typing_extensions import TypeAlias, TypeGuard
117-
118-
try: # pragma: no cover
119-
anext # noqa: B018 # pyright: ignore
120-
except NameError: # pragma: no cover (Python < 3.10)
121-
122-
async def anext(iterator: AsyncIterator) -> Any:
123-
"""Return the next item from an async iterator."""
124-
return await iterator.__anext__()
110+
from typing import TypeAlias, TypeGuard
125111

112+
from ..pyutils import UndefinedType
126113

127114
__all__ = [
128115
"ExecutionContext",
@@ -577,7 +564,7 @@ async def get_results() -> GraphQLWrappedResult[dict[str, Any]]:
577564
awaited_results = await gather_with_cancel(
578565
*(results[field] for field in awaitable_fields)
579566
)
580-
results.update(zip(awaitable_fields, awaited_results))
567+
results.update(zip(awaitable_fields, awaited_results, strict=True))
581568

582569
return GraphQLWrappedResult(results, graphql_wrapped_result.increments)
583570

@@ -654,10 +641,6 @@ async def await_completed() -> Any:
654641
try:
655642
return await completed
656643
except Exception as raw_error:
657-
# Before Python 3.8 CancelledError inherits Exception and
658-
# so gets caught here.
659-
if isinstance(raw_error, CancelledError):
660-
raise # pragma: no cover
661644
self.handle_field_error(
662645
raw_error,
663646
return_type,
@@ -867,10 +850,6 @@ async def complete_awaitable_value(
867850
if self.is_awaitable(completed):
868851
completed = await completed
869852
except Exception as raw_error:
870-
# Before Python 3.8 CancelledError inherits Exception and
871-
# so gets caught here.
872-
if isinstance(raw_error, CancelledError):
873-
raise # pragma: no cover
874853
self.handle_field_error(
875854
raw_error, return_type, field_group, path, incremental_context
876855
)
@@ -1040,7 +1019,9 @@ async def complete_async_iterator_value(
10401019
awaited_results = await gather_with_cancel(
10411020
*(completed_results[index] for index in awaitable_indices)
10421021
)
1043-
for index, sub_result in zip(awaitable_indices, awaited_results):
1022+
for index, sub_result in zip(
1023+
awaitable_indices, awaited_results, strict=True
1024+
):
10441025
completed_results[index] = sub_result
10451026
return GraphQLWrappedResult(
10461027
completed_results, graphql_wrapped_result.increments
@@ -1186,7 +1167,9 @@ async def get_completed_results() -> GraphQLWrappedResult[list[Any]]:
11861167
awaited_results = await gather_with_cancel(
11871168
*(completed_results[index] for index in awaitable_indices)
11881169
)
1189-
for index, sub_result in zip(awaitable_indices, awaited_results):
1170+
for index, sub_result in zip(
1171+
awaitable_indices, awaited_results, strict=True
1172+
):
11901173
completed_results[index] = sub_result
11911174
return GraphQLWrappedResult(
11921175
completed_results, graphql_wrapped_result.increments
@@ -2449,7 +2432,9 @@ def default_type_resolver(
24492432

24502433
async def get_type() -> str | None:
24512434
is_type_of_results = await gather_with_cancel(*awaitable_is_type_of_results)
2452-
for is_type_of_result, type_ in zip(is_type_of_results, awaitable_types):
2435+
for is_type_of_result, type_ in zip(
2436+
is_type_of_results, awaitable_types, strict=True
2437+
):
24532438
if is_type_of_result:
24542439
return type_.name
24552440
return None

src/graphql/execution/incremental_graph.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
)
3434

3535
if TYPE_CHECKING:
36+
from typing import TypeGuard
37+
3638
from ..error.graphql_error import GraphQLError
3739
from .types import (
3840
DeferredFragmentRecord,
@@ -43,11 +45,6 @@
4345
SubsequentResultRecord,
4446
)
4547

46-
try:
47-
from typing import TypeGuard
48-
except ImportError: # Python < 3.10
49-
from typing_extensions import TypeGuard
50-
5148
__all__ = ["IncrementalGraph"]
5249

5350

src/graphql/execution/incremental_publisher.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Any,
1010
AsyncGenerator,
1111
NamedTuple,
12+
Protocol,
1213
Sequence,
1314
cast,
1415
)
@@ -27,11 +28,6 @@
2728
is_non_reconcilable_deferred_grouped_field_set_result,
2829
)
2930

30-
try:
31-
from typing import Protocol
32-
except ImportError: # Python < 3.8
33-
from typing_extensions import Protocol
34-
3531
if TYPE_CHECKING:
3632
from ..error import GraphQLError
3733
from .types import (

src/graphql/execution/middleware.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44

55
from functools import partial, reduce
66
from inspect import isfunction
7-
from typing import Any, Callable, Iterator
8-
9-
try:
10-
from typing import TypeAlias
11-
except ImportError: # Python < 3.10
12-
from typing_extensions import TypeAlias
13-
7+
from typing import Any, Callable, Iterator, TypeAlias
148

159
__all__ = ["MiddlewareManager"]
1610

src/graphql/execution/types.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,20 @@
1010
Callable,
1111
Iterator,
1212
NamedTuple,
13+
TypeAlias,
14+
TypedDict,
1315
TypeVar,
1416
Union,
1517
)
1618

17-
try:
18-
from typing import TypedDict
19-
except ImportError: # Python < 3.8
20-
from typing_extensions import TypedDict
21-
try:
22-
from typing import TypeAlias
23-
except ImportError: # Python < 3.10
24-
from typing_extensions import TypeAlias
25-
2619
from ..pyutils import BoxedAwaitableOrValue, Undefined
2720

2821
if TYPE_CHECKING:
22+
from typing import TypeGuard
23+
2924
from ..error import GraphQLError, GraphQLFormattedError
3025
from ..pyutils import Path
3126

32-
try:
33-
from typing import TypeGuard
34-
except ImportError: # Python < 3.10
35-
from typing_extensions import TypeGuard
3627
try:
3728
from typing import NotRequired
3829
except ImportError: # Python < 3.11
@@ -779,10 +770,8 @@ def is_deferred_grouped_field_set_result(
779770
"""Check if the subsequent result is a deferred grouped field set result."""
780771
return isinstance(
781772
subsequent_result,
782-
(
783-
ReconcilableDeferredGroupedFieldSetResult,
784-
NonReconcilableDeferredGroupedFieldSetResult,
785-
), # we could use the union type here in Python >= 3.10
773+
ReconcilableDeferredGroupedFieldSetResult
774+
| NonReconcilableDeferredGroupedFieldSetResult,
786775
)
787776

788777

src/graphql/execution/values.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Any, Callable, Collection, Dict, List, Union
5+
from typing import Any, Callable, Collection, Dict, List, TypeAlias, Union
66

77
from ..error import GraphQLError
88
from ..language import (
@@ -34,11 +34,6 @@
3434
from ..utilities.type_from_ast import type_from_ast
3535
from ..utilities.value_from_ast import value_from_ast
3636

37-
try:
38-
from typing import TypeAlias
39-
except ImportError: # Python < 3.10
40-
from typing_extensions import TypeAlias
41-
4237
__all__ = ["get_argument_values", "get_directive_values", "get_variable_values"]
4338

4439
CoercedVariableValues: TypeAlias = Union[List[GraphQLError], Dict[str, Any]]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy