|
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] |
| 34 | + |
33 | 35 | try: |
34 | 36 | import markdown |
35 | | - def apply_markdown(text: str) -> str: ... |
36 | | - |
37 | | -except ImportError: |
38 | | - apply_markdown = None # type: ignore |
39 | | - markdown = None # type: ignore |
40 | | - |
41 | | -if markdown is not None and pygments is not None: |
42 | 37 | from markdown.preprocessors import Preprocessor |
| 38 | + def apply_markdown(text: str) -> str: ... |
43 | 39 |
|
44 | 40 | class CodeBlockPreprocessor(Preprocessor): |
45 | 41 | pattern: Any |
46 | 42 | formatter: Any |
47 | 43 | def run(self, lines: list[str]) -> list[str]: ... |
48 | 44 |
|
| 45 | +except ImportError: |
| 46 | + apply_markdown: TypeAlias = None # type: ignore[no-redef] |
| 47 | + markdown: TypeAlias = None # type: ignore[no-redef] |
| 48 | + |
49 | 49 | def pygments_css(style: Any) -> str | None: ... |
50 | 50 | def pygments_highlight(text: str, lang: str, style: Any) -> Any: ... |
51 | 51 | def md_filter_add_syntax_highlight(md: Any) -> bool: ... |
|
0 commit comments