diff --git a/pyproject.toml b/pyproject.toml index 59b87fb6b..7532072c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,10 +40,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..bd12eafde 100644 --- a/rest_framework-stubs/compat.pyi +++ b/rest_framework-stubs/compat.pyi @@ -1,51 +1,51 @@ 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 - -if markdown is not None and pygments is not None: from markdown.preprocessors import Preprocessor + def apply_markdown(text: str) -> str: ... class CodeBlockPreprocessor(Preprocessor): pattern: Any formatter: Any def run(self, lines: list[str]) -> list[str]: ... +except ImportError: + apply_markdown: TypeAlias = None # type: ignore[no-redef] + markdown: TypeAlias = None # type: ignore[no-redef] + 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: ...