|
1 | 1 | from typing import Any
|
2 | 2 |
|
3 | 3 | from django.db.models import QuerySet
|
| 4 | +from typing_extensions import TypeAlias |
4 | 5 |
|
5 | 6 | try:
|
6 | 7 | from django.contrib.postgres import fields as postgres_fields
|
7 | 8 | except ImportError:
|
8 |
| - postgres_fields = None # type: ignore |
| 9 | + postgres_fields: TypeAlias = None # type: ignore[no-redef] |
9 | 10 | try:
|
10 | 11 | import coreapi
|
11 | 12 | except ImportError:
|
12 |
| - coreapi = None |
| 13 | + coreapi: TypeAlias = None # type: ignore[no-redef] |
13 | 14 | try:
|
14 | 15 | import uritemplate
|
15 | 16 | except ImportError:
|
16 |
| - uritemplate = None # type: ignore |
| 17 | + uritemplate: TypeAlias = None # type: ignore[no-redef] |
17 | 18 | try:
|
18 | 19 | import coreschema
|
19 | 20 | except ImportError:
|
20 |
| - coreschema = None |
| 21 | + coreschema: TypeAlias = None # type: ignore[no-redef] |
21 | 22 | try:
|
22 | 23 | import yaml
|
23 | 24 | except ImportError:
|
24 |
| - yaml = None # type: ignore |
| 25 | + yaml: TypeAlias = None # type: ignore[no-redef] |
25 | 26 | try:
|
26 | 27 | import requests
|
27 | 28 | except ImportError:
|
28 |
| - requests = None # type: ignore |
| 29 | + requests: TypeAlias = None # type: ignore[no-redef] |
29 | 30 | try:
|
30 | 31 | import pygments
|
31 | 32 | except ImportError:
|
32 |
| - pygments = None |
| 33 | + pygments: TypeAlias = None # type: ignore[no-redef] |
33 | 34 | try:
|
34 | 35 | import markdown
|
35 | 36 | def apply_markdown(text: str) -> str: ...
|
36 | 37 |
|
37 | 38 | except ImportError:
|
38 |
| - apply_markdown = None # type: ignore |
39 |
| - markdown = None # type: ignore |
| 39 | + apply_markdown: TypeAlias = None # type: ignore[no-redef] |
| 40 | + markdown: TypeAlias = None # type: ignore[no-redef] |
40 | 41 |
|
41 |
| -if markdown is not None and pygments is not None: |
| 42 | +try: |
| 43 | + import pygments |
42 | 44 | from markdown.preprocessors import Preprocessor
|
43 | 45 |
|
44 | 46 | class CodeBlockPreprocessor(Preprocessor):
|
45 | 47 | pattern: Any
|
46 | 48 | formatter: Any
|
47 | 49 | def run(self, lines: list[str]) -> list[str]: ...
|
48 | 50 |
|
| 51 | +except ImportError: |
| 52 | + pass |
| 53 | + |
49 | 54 | def pygments_css(style: Any) -> str | None: ...
|
50 | 55 | def pygments_highlight(text: str, lang: str, style: Any) -> Any: ...
|
51 | 56 | def md_filter_add_syntax_highlight(md: Any) -> bool: ...
|
|
0 commit comments