From 322bbd7e15da8bb1e62a21c18498f97e23a759ee Mon Sep 17 00:00:00 2001 From: Daverball Date: Tue, 21 Nov 2023 22:56:29 +0100 Subject: [PATCH] Apply suggestions from code review --- stubs/fanstatic/fanstatic/compiler.pyi | 14 +++++++++----- stubs/fanstatic/fanstatic/core.pyi | 13 ++++++++----- stubs/fanstatic/fanstatic/injector.pyi | 6 +++--- stubs/fanstatic/fanstatic/publisher.pyi | 2 +- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/stubs/fanstatic/fanstatic/compiler.pyi b/stubs/fanstatic/fanstatic/compiler.pyi index 0ecf68e74f45..20006784bdcb 100644 --- a/stubs/fanstatic/fanstatic/compiler.pyi +++ b/stubs/fanstatic/fanstatic/compiler.pyi @@ -2,7 +2,7 @@ from _typeshed import StrOrBytesPath from abc import abstractmethod from logging import Logger from subprocess import Popen -from typing import Any, ClassVar +from typing import Any, ClassVar, NewType from typing_extensions import Literal import setuptools.command.sdist @@ -53,8 +53,10 @@ class NullCompiler(Compiler): @property def available(self) -> Literal[False]: ... -SOURCE: object -TARGET: object +_SourceType = NewType("_SourceType", object) +_TargetType = NewType("_TargetType", object) +SOURCE: _SourceType +TARGET: _TargetType class CommandlineBase: @property @@ -63,13 +65,15 @@ class CommandlineBase: arguments: ClassVar[list[str]] @property def available(self) -> bool: ... - def process(self, source: StrOrBytesPath, target: StrOrBytesPath) -> Popen[str]: ... + def process(self, source: StrOrBytesPath | _SourceType, target: StrOrBytesPath | _TargetType) -> Popen[str]: ... class CoffeeScript(CommandlineBase, Compiler): name: ClassVar[Literal["coffee"]] command: ClassVar[Literal["coffee"]] source_extension = NotImplemented - def process(self, source: StrOrBytesPath, target: StrOrBytesPath) -> None: ... # type:ignore[override] + def process( + self, source: StrOrBytesPath | _SourceType, target: StrOrBytesPath | _TargetType + ) -> None: ... # type:ignore[override] COFFEE_COMPILER: CoffeeScript diff --git a/stubs/fanstatic/fanstatic/core.pyi b/stubs/fanstatic/fanstatic/core.pyi index 5885bab0e1e7..304c74328dad 100644 --- a/stubs/fanstatic/fanstatic/core.pyi +++ b/stubs/fanstatic/fanstatic/core.pyi @@ -2,6 +2,7 @@ from abc import abstractmethod from collections.abc import Callable, Iterable from threading import local from types import ModuleType +from typing import NewType from typing_extensions import Literal, TypeAlias from fanstatic.compiler import Compiler, Minifier @@ -96,7 +97,8 @@ class Asset(Dependable): def set_dependencies(self, depends: Iterable[Dependable] | None) -> None: ... def list_assets(self) -> set[Asset]: ... -NOTHING: object +_NothingType = NewType("_NothingType", object) +NOTHING: _NothingType class Resource(Renderable, Asset): relpath: str @@ -123,8 +125,8 @@ class Resource(Renderable, Asset): debug: str | Resource | None = None, dont_bundle: bool = False, minified: str | Resource | None = None, - minifier: Minifier = ..., - compiler: Compiler = ..., + minifier: Minifier | _NothingType = ..., + compiler: Compiler | _NothingType = ..., source: str | None = None, mode_parent: str | None = None, ) -> None: ... @@ -134,7 +136,8 @@ class Resource(Renderable, Asset): def mode(self, mode: str | None) -> Resource: ... def need(self, slots: dict[Slot, Resource] | None = None) -> None: ... -REQUIRED_DEFAULT_MARKER: object +_RequiredDefaultMarkerType = NewType("_RequiredDefaultMarkerType", object) +REQUIRED_DEFAULT_MARKER: _RequiredDefaultMarkerType class Slot(Asset): default: Resource | None @@ -145,7 +148,7 @@ class Slot(Asset): library: Library, extension: str, depends: Iterable[Dependable] | None = None, - required: bool = ..., + required: bool | _RequiredDefaultMarkerType = ..., default: Resource | None = None, ) -> None: ... diff --git a/stubs/fanstatic/fanstatic/injector.pyi b/stubs/fanstatic/fanstatic/injector.pyi index 0b2fc5618802..e76a7c878c9b 100644 --- a/stubs/fanstatic/fanstatic/injector.pyi +++ b/stubs/fanstatic/fanstatic/injector.pyi @@ -2,7 +2,7 @@ from _typeshed.wsgi import StartResponse, WSGIApplication, WSGIEnvironment from abc import abstractmethod from collections.abc import Iterable from typing import Any -from typing_extensions import Literal, TypedDict +from typing_extensions import Literal, TypedDict, Unpack from fanstatic.core import Dependable, NeededResources, Resource from fanstatic.inclusion import Inclusion @@ -35,8 +35,8 @@ class Injector: config: _NeededResourcesConfig injector: InjectorPlugin def __init__( - self, app: WSGIApplication, injector: InjectorPlugin | None = None, **config: Any - ) -> None: ... # FIXME: Switch to Unpack[_NeededResourcesConfig] + self, app: WSGIApplication, injector: InjectorPlugin | None = None, **config: Unpack[_NeededResourcesConfig] + ) -> None: ... def __call__(self, environ: WSGIEnvironment, start_response: StartResponse) -> Iterable[bytes]: ... class InjectorPlugin: diff --git a/stubs/fanstatic/fanstatic/publisher.pyi b/stubs/fanstatic/fanstatic/publisher.pyi index 12ac3386c891..0e2ecf483e13 100644 --- a/stubs/fanstatic/fanstatic/publisher.pyi +++ b/stubs/fanstatic/fanstatic/publisher.pyi @@ -1,5 +1,5 @@ from _typeshed import StrOrBytesPath -from _typeshed.wsgi import StartResponse, WSGIApplication +from _typeshed.wsgi import StartResponse, WSGIApplication, WSGIEnvironment from collections.abc import Iterable from typing import IO, Any from typing_extensions import Literal