From fad94a126ea84ddcc8cef3addef7ba1e58ad9e25 Mon Sep 17 00:00:00 2001 From: Michael Dubner Date: Wed, 30 Nov 2022 08:32:08 +0300 Subject: [PATCH 1/7] Add stubs for dockerfile-parse --- pyrightconfig.stricter.json | 1 + stubs/dockerfile-parse/METADATA.toml | 4 ++ .../dockerfile_parse/__init__.pyi | 3 + .../dockerfile_parse/constants.pyi | 3 + .../dockerfile_parse/parser.pyi | 67 +++++++++++++++++++ .../dockerfile_parse/util.pyi | 46 +++++++++++++ 6 files changed, 124 insertions(+) create mode 100644 stubs/dockerfile-parse/METADATA.toml create mode 100644 stubs/dockerfile-parse/dockerfile_parse/__init__.pyi create mode 100644 stubs/dockerfile-parse/dockerfile_parse/constants.pyi create mode 100644 stubs/dockerfile-parse/dockerfile_parse/parser.pyi create mode 100644 stubs/dockerfile-parse/dockerfile_parse/util.pyi diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 06d11f1a33b9..29ea28e9150b 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -30,6 +30,7 @@ "stubs/commonmark", "stubs/cryptography", "stubs/dateparser", + "stubs/dockerfile-parse", "stubs/docutils", "stubs/Flask-Migrate", "stubs/Flask-SQLAlchemy", diff --git a/stubs/dockerfile-parse/METADATA.toml b/stubs/dockerfile-parse/METADATA.toml new file mode 100644 index 000000000000..8d199dc3bda1 --- /dev/null +++ b/stubs/dockerfile-parse/METADATA.toml @@ -0,0 +1,4 @@ +version = "1.2.*" + +[tool.stubtest] +ignore_missing_stub = false diff --git a/stubs/dockerfile-parse/dockerfile_parse/__init__.pyi b/stubs/dockerfile-parse/dockerfile_parse/__init__.pyi new file mode 100644 index 000000000000..eeb43a016a3a --- /dev/null +++ b/stubs/dockerfile-parse/dockerfile_parse/__init__.pyi @@ -0,0 +1,3 @@ +from .parser import DockerfileParser as DockerfileParser + +__version__: str diff --git a/stubs/dockerfile-parse/dockerfile_parse/constants.pyi b/stubs/dockerfile-parse/dockerfile_parse/constants.pyi new file mode 100644 index 000000000000..7b7fc8fa18f3 --- /dev/null +++ b/stubs/dockerfile-parse/dockerfile_parse/constants.pyi @@ -0,0 +1,3 @@ +PY2: bool +DOCKERFILE_FILENAME: str +COMMENT_INSTRUCTION: str diff --git a/stubs/dockerfile-parse/dockerfile_parse/parser.pyi b/stubs/dockerfile-parse/dockerfile_parse/parser.pyi new file mode 100644 index 000000000000..a75e6ac5f43d --- /dev/null +++ b/stubs/dockerfile-parse/dockerfile_parse/parser.pyi @@ -0,0 +1,67 @@ +import logging +import typing as t +from contextlib import contextmanager + +logger: logging.Logger + +class KeyValues(dict[str, str]): + parser_attr: str + parser: DockerfileParser + def __init__(self, key_values: dict[str, str], parser: DockerfileParser) -> None: ... + def __delitem__(self, key: str) -> None: ... + def __setitem__(self, key: str, value: str) -> None: ... + def __eq__(self, other) -> bool: ... + def __hash__(self) -> int: ... # type: ignore + +class Labels(KeyValues): + parser_attr: str + +class Envs(KeyValues): + parser_attr: str + +class Args(KeyValues): + parser_attr: str + +class DockerfileParser: + fileobj: t.IO[str] + dockerfile_path: str | None + cache_content: bool + cached_content: str + env_replace: bool + parent_env: t.Mapping[str, str] + build_args: t.Mapping[str, str] + def __init__( + self, + path: str | None = ..., + cache_content: bool = ..., + env_replace: bool = ..., + parent_env: t.Mapping[str, str] | None = ..., + fileobj: t.IO[str] | None = ..., + build_args: t.Mapping[str, str] | None = ..., + ) -> None: ... + @contextmanager + def _open_dockerfile(self, mode: str) -> t.IO: ... + lines: t.Sequence[str] + content: str + @property + def structure(self) -> list[dict[str, t.Any]]: ... + @property + def json(self) -> str: ... + parent_images: t.Sequence[str] + @property + def is_multistage(self) -> bool: ... + baseimage: str + cmd: str + labels: t.Mapping[str, str] + envs: t.Mapping[str, str] + args: t.Mapping[str, str] + def add_lines( + self, *lines: list[str], all_stages: bool | None = ..., at_start: bool | None = ..., skip_scratch: bool | None = ... + ) -> None: ... + def add_lines_at( + self, anchor: str | int | dict[str, int], *lines: list[str], replace: bool | None = ..., after: bool | None = ... + ) -> None: ... + @property + def context_structure(self) -> list[str]: ... + +def image_from(from_value: str) -> tuple[str, str | None]: ... diff --git a/stubs/dockerfile-parse/dockerfile_parse/util.pyi b/stubs/dockerfile-parse/dockerfile_parse/util.pyi new file mode 100644 index 000000000000..3525458670e9 --- /dev/null +++ b/stubs/dockerfile-parse/dockerfile_parse/util.pyi @@ -0,0 +1,46 @@ +import typing as t +from collections.abc import Generator +from typing_extensions import TypeAlias + +def b2u(string: bytes | str) -> str: ... +def u2b(string: str | bytes) -> bytes: ... + +_Quotes: TypeAlias = t.Literal["'", '"'] # NOQA: Y020 +_ContextType: TypeAlias = t.Literal["ARG", "ENV", "LABEL"] # NOQA: Y020 + +class WordSplitter: + SQUOTE: _Quotes + DQUOTE: _Quotes + stream: t.IO[str] + args: t.Mapping[str, str] + envs: t.Mapping[str, str] + quotes: _Quotes + escaped: bool + def __init__(self, s: str, args: t.Mapping[str, str] | None = ..., envs: t.Mapping[str, str] | None = ...) -> None: ... + def dequote(self) -> str: ... + def split(self, maxsplit: int | None = ..., dequote: bool = ...) -> Generator[str | None, None, None]: ... + +def extract_key_values(env_replace: bool, args: t.Mapping[str, str], envs: t.Mapping[str, str], instruction_value: str): ... +def get_key_val_dictionary( + instruction_value, env_replace: bool = ..., args: t.Mapping[str, str] | None = ..., envs: t.Mapping[str, str] | None = ... +): ... + +class Context: + args: t.Mapping[str, str] + envs: t.Mapping[str, str] + labels: t.Mapping[str, str] + line_args: t.Mapping[str, str] + line_envs: t.Mapping[str, str] + line_labels: t.Mapping[str, str] + def __init__( + self, + args: t.Mapping[str, str] | None = ..., + envs: t.Mapping[str, str] | None = ..., + labels: t.Mapping[str, str] | None = ..., + line_args: t.Mapping[str, str] | None = ..., + line_envs: t.Mapping[str, str] | None = ..., + line_labels: t.Mapping[str, str] | None = ..., + ) -> None: ... + def set_line_value(self, context_type: _ContextType, value: t.Mapping[str, str]) -> None: ... + def get_line_value(self, context_type: _ContextType) -> t.Mapping[str, str]: ... + def get_values(self, context_type: _ContextType) -> t.Mapping[str, str]: ... From 9066bd037dc9a21dcc6ad295d24942e34a6aa463 Mon Sep 17 00:00:00 2001 From: Michael Dubner Date: Wed, 30 Nov 2022 18:09:51 +0300 Subject: [PATCH 2/7] make stubtest and pyright happy: use typing_extensions.Literal instead of typing.Literal + reimport wuth "X as X" all imported values --- .../dockerfile_parse/constants.pyi | 2 ++ .../dockerfile_parse/parser.pyi | 17 ++++++++++++++--- .../dockerfile-parse/dockerfile_parse/util.pyi | 8 +++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/stubs/dockerfile-parse/dockerfile_parse/constants.pyi b/stubs/dockerfile-parse/dockerfile_parse/constants.pyi index 7b7fc8fa18f3..79efafda5e52 100644 --- a/stubs/dockerfile-parse/dockerfile_parse/constants.pyi +++ b/stubs/dockerfile-parse/dockerfile_parse/constants.pyi @@ -1,3 +1,5 @@ +from sys import version_info as version_info + PY2: bool DOCKERFILE_FILENAME: str COMMENT_INSTRUCTION: str diff --git a/stubs/dockerfile-parse/dockerfile_parse/parser.pyi b/stubs/dockerfile-parse/dockerfile_parse/parser.pyi index a75e6ac5f43d..19cafe0e64ce 100644 --- a/stubs/dockerfile-parse/dockerfile_parse/parser.pyi +++ b/stubs/dockerfile-parse/dockerfile_parse/parser.pyi @@ -2,10 +2,14 @@ import logging import typing as t from contextlib import contextmanager +from six import string_types as string_types + +from .constants import COMMENT_INSTRUCTION as COMMENT_INSTRUCTION, DOCKERFILE_FILENAME as DOCKERFILE_FILENAME + logger: logging.Logger class KeyValues(dict[str, str]): - parser_attr: str + parser_attr: str | None parser: DockerfileParser def __init__(self, key_values: dict[str, str], parser: DockerfileParser) -> None: ... def __delitem__(self, key: str) -> None: ... @@ -22,6 +26,13 @@ class Envs(KeyValues): class Args(KeyValues): parser_attr: str +class _InstructionDict(t.TypedDict): + instruction: str + startline: int + endline: int + content: str + value: str + class DockerfileParser: fileobj: t.IO[str] dockerfile_path: str | None @@ -40,11 +51,11 @@ class DockerfileParser: build_args: t.Mapping[str, str] | None = ..., ) -> None: ... @contextmanager - def _open_dockerfile(self, mode: str) -> t.IO: ... + def _open_dockerfile(self, mode: str) -> t.Iterator[t.IO[str]]: ... lines: t.Sequence[str] content: str @property - def structure(self) -> list[dict[str, t.Any]]: ... + def structure(self) -> list[_InstructionDict]: ... @property def json(self) -> str: ... parent_images: t.Sequence[str] diff --git a/stubs/dockerfile-parse/dockerfile_parse/util.pyi b/stubs/dockerfile-parse/dockerfile_parse/util.pyi index 3525458670e9..b484020e6f85 100644 --- a/stubs/dockerfile-parse/dockerfile_parse/util.pyi +++ b/stubs/dockerfile-parse/dockerfile_parse/util.pyi @@ -1,12 +1,14 @@ import typing as t from collections.abc import Generator -from typing_extensions import TypeAlias +from typing_extensions import Literal, TypeAlias + +from .constants import PY2 as PY2 def b2u(string: bytes | str) -> str: ... def u2b(string: str | bytes) -> bytes: ... -_Quotes: TypeAlias = t.Literal["'", '"'] # NOQA: Y020 -_ContextType: TypeAlias = t.Literal["ARG", "ENV", "LABEL"] # NOQA: Y020 +_Quotes: TypeAlias = Literal["'", '"'] +_ContextType: TypeAlias = Literal["ARG", "ENV", "LABEL"] class WordSplitter: SQUOTE: _Quotes From ae0e66bf90fc0d063bc876338d83e250b312d7df Mon Sep 17 00:00:00 2001 From: Michael Dubner Date: Wed, 30 Nov 2022 18:27:25 +0300 Subject: [PATCH 3/7] add types-six to requirements + use typing_extensions.TypedDict instead of typing.TypedDict --- requirements-tests.txt | 1 + stubs/dockerfile-parse/dockerfile_parse/parser.pyi | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 24c8c5822856..d311c48a12a9 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -15,3 +15,4 @@ termcolor>=2 tomli==2.0.1 tomlkit==0.11.6 types-pyyaml +types-six diff --git a/stubs/dockerfile-parse/dockerfile_parse/parser.pyi b/stubs/dockerfile-parse/dockerfile_parse/parser.pyi index 19cafe0e64ce..fb9b33a01f55 100644 --- a/stubs/dockerfile-parse/dockerfile_parse/parser.pyi +++ b/stubs/dockerfile-parse/dockerfile_parse/parser.pyi @@ -1,6 +1,7 @@ import logging import typing as t from contextlib import contextmanager +from typing_extensions import TypedDict from six import string_types as string_types @@ -26,7 +27,7 @@ class Envs(KeyValues): class Args(KeyValues): parser_attr: str -class _InstructionDict(t.TypedDict): +class _InstructionDict(TypedDict): instruction: str startline: int endline: int From 4fbbb719e1cc3512a642954b8a071db05d1df8a8 Mon Sep 17 00:00:00 2001 From: Michael Dubner Date: Wed, 30 Nov 2022 18:38:15 +0300 Subject: [PATCH 4/7] requires = ["types-six"] to dockerfile-parse/METADATA.toml --- requirements-tests.txt | 1 - stubs/dockerfile-parse/METADATA.toml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index d311c48a12a9..24c8c5822856 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -15,4 +15,3 @@ termcolor>=2 tomli==2.0.1 tomlkit==0.11.6 types-pyyaml -types-six diff --git a/stubs/dockerfile-parse/METADATA.toml b/stubs/dockerfile-parse/METADATA.toml index 8d199dc3bda1..beccf3359d97 100644 --- a/stubs/dockerfile-parse/METADATA.toml +++ b/stubs/dockerfile-parse/METADATA.toml @@ -1,4 +1,5 @@ version = "1.2.*" +requires = ["types-six"] [tool.stubtest] ignore_missing_stub = false From 1f3cf138705f64ab3b0aabb09d3e4fbcb3c8c944 Mon Sep 17 00:00:00 2001 From: Michael Dubner Date: Thu, 1 Dec 2022 00:46:17 +0300 Subject: [PATCH 5/7] Implemented a lot of suggestions of @AlexWaygood. --- .../dockerfile_parse/constants.pyi | 4 +- .../dockerfile_parse/parser.pyi | 49 +++++++------------ .../dockerfile_parse/util.pyi | 27 +++++----- 3 files changed, 33 insertions(+), 47 deletions(-) diff --git a/stubs/dockerfile-parse/dockerfile_parse/constants.pyi b/stubs/dockerfile-parse/dockerfile_parse/constants.pyi index 79efafda5e52..31d0e73bc015 100644 --- a/stubs/dockerfile-parse/dockerfile_parse/constants.pyi +++ b/stubs/dockerfile-parse/dockerfile_parse/constants.pyi @@ -1,5 +1,5 @@ -from sys import version_info as version_info +from typing_extensions import Literal -PY2: bool +PY2: Literal[False] DOCKERFILE_FILENAME: str COMMENT_INSTRUCTION: str diff --git a/stubs/dockerfile-parse/dockerfile_parse/parser.pyi b/stubs/dockerfile-parse/dockerfile_parse/parser.pyi index fb9b33a01f55..6f3dde0c9ba5 100644 --- a/stubs/dockerfile-parse/dockerfile_parse/parser.pyi +++ b/stubs/dockerfile-parse/dockerfile_parse/parser.pyi @@ -1,31 +1,20 @@ -import logging import typing as t -from contextlib import contextmanager from typing_extensions import TypedDict -from six import string_types as string_types - -from .constants import COMMENT_INSTRUCTION as COMMENT_INSTRUCTION, DOCKERFILE_FILENAME as DOCKERFILE_FILENAME - -logger: logging.Logger +from .util import Context class KeyValues(dict[str, str]): - parser_attr: str | None + parser_attr: t.ClassVar[str | None] parser: DockerfileParser - def __init__(self, key_values: dict[str, str], parser: DockerfileParser) -> None: ... + def __init__(self, key_values: t.Mapping[str, str], parser: DockerfileParser) -> None: ... def __delitem__(self, key: str) -> None: ... def __setitem__(self, key: str, value: str) -> None: ... - def __eq__(self, other) -> bool: ... - def __hash__(self) -> int: ... # type: ignore - -class Labels(KeyValues): - parser_attr: str - -class Envs(KeyValues): - parser_attr: str + def __eq__(self, other: object) -> bool: ... + def __hash__(self) -> int: ... # type: ignore[override] -class Args(KeyValues): - parser_attr: str +class Labels(KeyValues): ... +class Envs(KeyValues): ... +class Args(KeyValues): ... class _InstructionDict(TypedDict): instruction: str @@ -36,24 +25,22 @@ class _InstructionDict(TypedDict): class DockerfileParser: fileobj: t.IO[str] - dockerfile_path: str | None + dockerfile_path: str cache_content: bool cached_content: str env_replace: bool - parent_env: t.Mapping[str, str] - build_args: t.Mapping[str, str] + parent_env: dict[str, str] + build_args: dict[str, str] def __init__( self, path: str | None = ..., cache_content: bool = ..., env_replace: bool = ..., - parent_env: t.Mapping[str, str] | None = ..., + parent_env: dict[str, str] | None = ..., fileobj: t.IO[str] | None = ..., - build_args: t.Mapping[str, str] | None = ..., + build_args: dict[str, str] | None = ..., ) -> None: ... - @contextmanager - def _open_dockerfile(self, mode: str) -> t.Iterator[t.IO[str]]: ... - lines: t.Sequence[str] + lines: list[str] content: str @property def structure(self) -> list[_InstructionDict]: ... @@ -68,12 +55,12 @@ class DockerfileParser: envs: t.Mapping[str, str] args: t.Mapping[str, str] def add_lines( - self, *lines: list[str], all_stages: bool | None = ..., at_start: bool | None = ..., skip_scratch: bool | None = ... + self, *lines: str, all_stages: bool | None = ..., at_start: bool | None = ..., skip_scratch: bool | None = ... ) -> None: ... def add_lines_at( - self, anchor: str | int | dict[str, int], *lines: list[str], replace: bool | None = ..., after: bool | None = ... + self, anchor: str | int | dict[str, int], *lines: str, replace: bool | None = ..., after: bool | None = ... ) -> None: ... @property - def context_structure(self) -> list[str]: ... + def context_structure(self) -> list[Context]: ... -def image_from(from_value: str) -> tuple[str, str | None]: ... +def image_from(from_value: str) -> tuple[str | None, str | None]: ... diff --git a/stubs/dockerfile-parse/dockerfile_parse/util.pyi b/stubs/dockerfile-parse/dockerfile_parse/util.pyi index b484020e6f85..593332643b28 100644 --- a/stubs/dockerfile-parse/dockerfile_parse/util.pyi +++ b/stubs/dockerfile-parse/dockerfile_parse/util.pyi @@ -1,9 +1,8 @@ import typing as t from collections.abc import Generator +from io import StringIO from typing_extensions import Literal, TypeAlias -from .constants import PY2 as PY2 - def b2u(string: bytes | str) -> str: ... def u2b(string: str | bytes) -> bytes: ... @@ -11,12 +10,12 @@ _Quotes: TypeAlias = Literal["'", '"'] _ContextType: TypeAlias = Literal["ARG", "ENV", "LABEL"] class WordSplitter: - SQUOTE: _Quotes - DQUOTE: _Quotes - stream: t.IO[str] - args: t.Mapping[str, str] - envs: t.Mapping[str, str] - quotes: _Quotes + SQUOTE: t.ClassVar[_Quotes] + DQUOTE: t.ClassVar[_Quotes] + stream: StringIO + args: t.Mapping[str, str] | None + envs: t.Mapping[str, str] | None + quotes: _Quotes | None escaped: bool def __init__(self, s: str, args: t.Mapping[str, str] | None = ..., envs: t.Mapping[str, str] | None = ...) -> None: ... def dequote(self) -> str: ... @@ -28,17 +27,17 @@ def get_key_val_dictionary( ): ... class Context: - args: t.Mapping[str, str] - envs: t.Mapping[str, str] - labels: t.Mapping[str, str] + args: t.MutableMapping[str, str] + envs: t.MutableMapping[str, str] + labels: t.MutableMapping[str, str] line_args: t.Mapping[str, str] line_envs: t.Mapping[str, str] line_labels: t.Mapping[str, str] def __init__( self, - args: t.Mapping[str, str] | None = ..., - envs: t.Mapping[str, str] | None = ..., - labels: t.Mapping[str, str] | None = ..., + args: t.MutableMapping[str, str] | None = ..., + envs: t.MutableMapping[str, str] | None = ..., + labels: t.MutableMapping[str, str] | None = ..., line_args: t.Mapping[str, str] | None = ..., line_envs: t.Mapping[str, str] | None = ..., line_labels: t.Mapping[str, str] | None = ..., From c925c34ab2de059f9b297bb7ddced1448c9b2374 Mon Sep 17 00:00:00 2001 From: Michael Dubner Date: Thu, 1 Dec 2022 00:54:48 +0300 Subject: [PATCH 6/7] Add stubs/dockerfile-parse/@tests/stubtest_allowlist.txt --- stubs/dockerfile-parse/@tests/stubtest_allowlist.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 stubs/dockerfile-parse/@tests/stubtest_allowlist.txt diff --git a/stubs/dockerfile-parse/@tests/stubtest_allowlist.txt b/stubs/dockerfile-parse/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..0d91baed6589 --- /dev/null +++ b/stubs/dockerfile-parse/@tests/stubtest_allowlist.txt @@ -0,0 +1,6 @@ +# These are re-exports which we consider an implementation detail +dockerfile_parse.constants.version_info +dockerfile_parse.parser.string_types +dockerfile_parse.parser.DOCKERFILE_FILENAME +dockerfile_parse.parser.COMMENT_INSTRUCTION +dockerfile_parse.util.PY2 From 134b5b08095e0500407ceabbafa633775c28b322 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Wed, 30 Nov 2022 22:13:06 +0000 Subject: [PATCH 7/7] Fix a few minor style issues --- .../dockerfile_parse/parser.pyi | 19 ++++---- .../dockerfile_parse/util.pyi | 48 +++++++++---------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/stubs/dockerfile-parse/dockerfile_parse/parser.pyi b/stubs/dockerfile-parse/dockerfile_parse/parser.pyi index 6f3dde0c9ba5..73073c521411 100644 --- a/stubs/dockerfile-parse/dockerfile_parse/parser.pyi +++ b/stubs/dockerfile-parse/dockerfile_parse/parser.pyi @@ -1,12 +1,13 @@ -import typing as t +from collections.abc import Mapping, Sequence +from typing import IO, ClassVar from typing_extensions import TypedDict from .util import Context class KeyValues(dict[str, str]): - parser_attr: t.ClassVar[str | None] + parser_attr: ClassVar[str | None] parser: DockerfileParser - def __init__(self, key_values: t.Mapping[str, str], parser: DockerfileParser) -> None: ... + def __init__(self, key_values: Mapping[str, str], parser: DockerfileParser) -> None: ... def __delitem__(self, key: str) -> None: ... def __setitem__(self, key: str, value: str) -> None: ... def __eq__(self, other: object) -> bool: ... @@ -24,7 +25,7 @@ class _InstructionDict(TypedDict): value: str class DockerfileParser: - fileobj: t.IO[str] + fileobj: IO[str] dockerfile_path: str cache_content: bool cached_content: str @@ -37,7 +38,7 @@ class DockerfileParser: cache_content: bool = ..., env_replace: bool = ..., parent_env: dict[str, str] | None = ..., - fileobj: t.IO[str] | None = ..., + fileobj: IO[str] | None = ..., build_args: dict[str, str] | None = ..., ) -> None: ... lines: list[str] @@ -46,14 +47,14 @@ class DockerfileParser: def structure(self) -> list[_InstructionDict]: ... @property def json(self) -> str: ... - parent_images: t.Sequence[str] + parent_images: Sequence[str] @property def is_multistage(self) -> bool: ... baseimage: str cmd: str - labels: t.Mapping[str, str] - envs: t.Mapping[str, str] - args: t.Mapping[str, str] + labels: Mapping[str, str] + envs: Mapping[str, str] + args: Mapping[str, str] def add_lines( self, *lines: str, all_stages: bool | None = ..., at_start: bool | None = ..., skip_scratch: bool | None = ... ) -> None: ... diff --git a/stubs/dockerfile-parse/dockerfile_parse/util.pyi b/stubs/dockerfile-parse/dockerfile_parse/util.pyi index 593332643b28..a2304e96ae7b 100644 --- a/stubs/dockerfile-parse/dockerfile_parse/util.pyi +++ b/stubs/dockerfile-parse/dockerfile_parse/util.pyi @@ -1,6 +1,6 @@ -import typing as t -from collections.abc import Generator +from collections.abc import Generator, Mapping, MutableMapping from io import StringIO +from typing import ClassVar from typing_extensions import Literal, TypeAlias def b2u(string: bytes | str) -> str: ... @@ -10,38 +10,38 @@ _Quotes: TypeAlias = Literal["'", '"'] _ContextType: TypeAlias = Literal["ARG", "ENV", "LABEL"] class WordSplitter: - SQUOTE: t.ClassVar[_Quotes] - DQUOTE: t.ClassVar[_Quotes] + SQUOTE: ClassVar[_Quotes] + DQUOTE: ClassVar[_Quotes] stream: StringIO - args: t.Mapping[str, str] | None - envs: t.Mapping[str, str] | None + args: Mapping[str, str] | None + envs: Mapping[str, str] | None quotes: _Quotes | None escaped: bool - def __init__(self, s: str, args: t.Mapping[str, str] | None = ..., envs: t.Mapping[str, str] | None = ...) -> None: ... + def __init__(self, s: str, args: Mapping[str, str] | None = ..., envs: Mapping[str, str] | None = ...) -> None: ... def dequote(self) -> str: ... def split(self, maxsplit: int | None = ..., dequote: bool = ...) -> Generator[str | None, None, None]: ... -def extract_key_values(env_replace: bool, args: t.Mapping[str, str], envs: t.Mapping[str, str], instruction_value: str): ... +def extract_key_values(env_replace: bool, args: Mapping[str, str], envs: Mapping[str, str], instruction_value: str): ... def get_key_val_dictionary( - instruction_value, env_replace: bool = ..., args: t.Mapping[str, str] | None = ..., envs: t.Mapping[str, str] | None = ... + instruction_value, env_replace: bool = ..., args: Mapping[str, str] | None = ..., envs: Mapping[str, str] | None = ... ): ... class Context: - args: t.MutableMapping[str, str] - envs: t.MutableMapping[str, str] - labels: t.MutableMapping[str, str] - line_args: t.Mapping[str, str] - line_envs: t.Mapping[str, str] - line_labels: t.Mapping[str, str] + args: MutableMapping[str, str] + envs: MutableMapping[str, str] + labels: MutableMapping[str, str] + line_args: Mapping[str, str] + line_envs: Mapping[str, str] + line_labels: Mapping[str, str] def __init__( self, - args: t.MutableMapping[str, str] | None = ..., - envs: t.MutableMapping[str, str] | None = ..., - labels: t.MutableMapping[str, str] | None = ..., - line_args: t.Mapping[str, str] | None = ..., - line_envs: t.Mapping[str, str] | None = ..., - line_labels: t.Mapping[str, str] | None = ..., + args: MutableMapping[str, str] | None = ..., + envs: MutableMapping[str, str] | None = ..., + labels: MutableMapping[str, str] | None = ..., + line_args: Mapping[str, str] | None = ..., + line_envs: Mapping[str, str] | None = ..., + line_labels: Mapping[str, str] | None = ..., ) -> None: ... - def set_line_value(self, context_type: _ContextType, value: t.Mapping[str, str]) -> None: ... - def get_line_value(self, context_type: _ContextType) -> t.Mapping[str, str]: ... - def get_values(self, context_type: _ContextType) -> t.Mapping[str, str]: ... + def set_line_value(self, context_type: _ContextType, value: Mapping[str, str]) -> None: ... + def get_line_value(self, context_type: _ContextType) -> Mapping[str, str]: ... + def get_values(self, context_type: _ContextType) -> Mapping[str, str]: ...