Skip to content

Commit b63d975

Browse files
committed
Modernize TYPE_CHECKING blocks
1 parent 62a489f commit b63d975

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

pytest_django/asserts.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
Dynamically load all Django assertion cases and expose them for importing.
33
"""
44
from functools import wraps
5-
from typing import Any, Callable, Optional, Sequence, Set, Type, Union
5+
from typing import (
6+
TYPE_CHECKING, Any, Callable, Optional, Sequence, Set, Type, Union,
7+
)
68

79
from django.test import (
810
LiveServerTestCase, SimpleTestCase, TestCase, TransactionTestCase,
911
)
1012

1113

12-
TYPE_CHECKING = False
13-
14-
1514
test_case = TestCase("run")
1615

1716

pytest_django/fixtures.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import os
33
from contextlib import contextmanager
44
from functools import partial
5-
from typing import Any, Generator, Iterable, List, Optional, Tuple, Union
5+
from typing import (
6+
TYPE_CHECKING, Any, Generator, Iterable, List, Literal, Optional, Tuple,
7+
Union,
8+
)
69

710
import pytest
811

@@ -11,16 +14,14 @@
1114
from .lazy_django import skip_if_no_django
1215

1316

14-
TYPE_CHECKING = False
1517
if TYPE_CHECKING:
16-
from typing import Literal
17-
1818
import django
1919

20-
_DjangoDbDatabases = Optional[Union["Literal['__all__']", Iterable[str]]]
21-
_DjangoDbAvailableApps = Optional[List[str]]
22-
# transaction, reset_sequences, databases, serialized_rollback, available_apps
23-
_DjangoDb = Tuple[bool, bool, _DjangoDbDatabases, bool, _DjangoDbAvailableApps]
20+
21+
_DjangoDbDatabases = Optional[Union[Literal['__all__'], Iterable[str]]]
22+
_DjangoDbAvailableApps = Optional[List[str]]
23+
# transaction, reset_sequences, databases, serialized_rollback, available_apps
24+
_DjangoDb = Tuple[bool, bool, _DjangoDbDatabases, bool, _DjangoDbAvailableApps]
2425

2526

2627
__all__ = [
@@ -239,7 +240,7 @@ def tearDownClass(cls) -> None:
239240
request.addfinalizer(test_case._post_teardown)
240241

241242

242-
def validate_django_db(marker) -> "_DjangoDb":
243+
def validate_django_db(marker) -> _DjangoDb:
243244
"""Validate the django_db marker.
244245
245246
It checks the signature and creates the ``transaction``,
@@ -254,10 +255,10 @@ def validate_django_db(marker) -> "_DjangoDb":
254255
def apifun(
255256
transaction: bool = False,
256257
reset_sequences: bool = False,
257-
databases: "_DjangoDbDatabases" = None,
258+
databases: _DjangoDbDatabases = None,
258259
serialized_rollback: bool = False,
259-
available_apps: "_DjangoDbAvailableApps" = None,
260-
) -> "_DjangoDb":
260+
available_apps: _DjangoDbAvailableApps = None,
261+
) -> _DjangoDb:
261262
return transaction, reset_sequences, databases, serialized_rollback, available_apps
262263

263264
return apifun(*marker.args, **marker.kwargs)

pytest_django/plugin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
import pathlib
1111
import sys
1212
from functools import reduce
13-
from typing import Generator, List, Optional, Tuple, Union
13+
from typing import (
14+
TYPE_CHECKING, ContextManager, Generator, List, NoReturn, Optional, Tuple,
15+
Union,
16+
)
1417

1518
import pytest
1619

@@ -46,10 +49,7 @@
4649
from .lazy_django import django_settings_is_configured, skip_if_no_django
4750

4851

49-
TYPE_CHECKING = False
5052
if TYPE_CHECKING:
51-
from typing import ContextManager, NoReturn
52-
5353
import django
5454

5555

0 commit comments

Comments
 (0)