diff --git a/pyproject.toml b/pyproject.toml index 091200edf..0bcc8bd12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,10 +39,9 @@ ignore = ["PYI021", "PYI024", "PYI041", "PYI043"] "F405", "F822", "F821", - "PYI026", # TODO fix these errors "PGH003", # TODO fix these errors - "PYI002", # TODO fix these errors ] +"rest_framework-stubs/compat.pyi" = ["PYI042"] [tool.ruff.flake8-tidy-imports.banned-api] "_typeshed.Self".msg = "Use typing_extensions.Self (PEP 673) instead." diff --git a/rest_framework-stubs/compat.pyi b/rest_framework-stubs/compat.pyi index 3f3c243b8..883110ae3 100644 --- a/rest_framework-stubs/compat.pyi +++ b/rest_framework-stubs/compat.pyi @@ -1,44 +1,46 @@ from typing import Any from django.db.models import QuerySet +from typing_extensions import TypeAlias try: from django.contrib.postgres import fields as postgres_fields except ImportError: - postgres_fields = None # type: ignore + postgres_fields: TypeAlias = None # type: ignore[no-redef] try: import coreapi except ImportError: - coreapi = None + coreapi: TypeAlias = None # type: ignore[no-redef] try: import uritemplate except ImportError: - uritemplate = None # type: ignore + uritemplate: TypeAlias = None # type: ignore[no-redef] try: import coreschema except ImportError: - coreschema = None + coreschema: TypeAlias = None # type: ignore[no-redef] try: import yaml except ImportError: - yaml = None # type: ignore + yaml: TypeAlias = None # type: ignore[no-redef] try: import requests except ImportError: - requests = None # type: ignore + requests: TypeAlias = None # type: ignore[no-redef] try: import pygments except ImportError: - pygments = None + pygments: TypeAlias = None # type: ignore[no-redef] try: import markdown def apply_markdown(text: str) -> str: ... except ImportError: - apply_markdown = None # type: ignore - markdown = None # type: ignore + apply_markdown: TypeAlias = None # type: ignore[no-redef] + markdown: TypeAlias = None # type: ignore[no-redef] -if markdown is not None and pygments is not None: +try: + import pygments from markdown.preprocessors import Preprocessor class CodeBlockPreprocessor(Preprocessor): @@ -46,6 +48,9 @@ if markdown is not None and pygments is not None: formatter: Any def run(self, lines: list[str]) -> list[str]: ... +except ImportError: + pass + def pygments_css(style: Any) -> str | None: ... def pygments_highlight(text: str, lang: str, style: Any) -> Any: ... def md_filter_add_syntax_highlight(md: Any) -> bool: ...