Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some issues with the types #41

Merged
merged 3 commits into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 48 additions & 18 deletions nodejs_wheel/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,43 @@
import os
import subprocess
import sys
from typing import Any, Literal, overload
from typing import Any, Iterable, Literal, overload

ROOT_DIR = os.path.dirname(__file__)


@overload
def _program(
name: str, args: list[str], return_completed_process: Literal[True], **kwargs: Any
name: str,
args: Iterable[str],
return_completed_process: Literal[True],
**kwargs: Any,
) -> subprocess.CompletedProcess[str | bytes]: ...


@overload
def _program(
name: str, args: list[str], return_completed_process: Literal[False], **kwargs: Any
name: str,
args: Iterable[str],
return_completed_process: Literal[False] = ...,
**kwargs: Any,
) -> subprocess.CompletedProcess[str | bytes]: ...


@overload
def _program(
name: str, args: list[str], return_completed_process: bool = False, **kwargs: Any
name: str,
args: Iterable[str],
return_completed_process: bool = False,
**kwargs: Any,
) -> int | subprocess.CompletedProcess[str | bytes]: ...


def _program(
name: str, args: list[str], return_completed_process: bool = False, **kwargs: Any
name: str,
args: Iterable[str],
return_completed_process: bool = False,
**kwargs: Any,
) -> int | subprocess.CompletedProcess[str | bytes]:
bin_dir = ROOT_DIR if os.name == "nt" else os.path.join(ROOT_DIR, "bin")
complete_process = subprocess.run([os.path.join(bin_dir, name), *args], **kwargs)
Expand All @@ -44,7 +56,7 @@ def call_node(

@overload
def call_node(
*args: str, return_completed_process: Literal[False], **kwargs: Any
*args: str, return_completed_process: Literal[False] = ..., **kwargs: Any
) -> int: ...


Expand All @@ -68,24 +80,30 @@ def call_node(

@overload
def node(
args: list[str] | None, return_completed_process: Literal[True], **kwargs: Any
args: Iterable[str] | None, return_completed_process: Literal[True], **kwargs: Any
) -> subprocess.CompletedProcess[str | bytes]: ...


@overload
def node(
args: list[str] | None, return_completed_process: Literal[False], **kwargs: Any
args: Iterable[str] | None,
return_completed_process: Literal[False] = ...,
**kwargs: Any,
) -> int: ...


@overload
def node(
args: list[str] | None = None, return_completed_process: bool = False, **kwargs: Any
args: Iterable[str] | None = None,
return_completed_process: bool = False,
**kwargs: Any,
) -> int | subprocess.CompletedProcess[str | bytes]: ...


def node(
args: list[str] | None = None, return_completed_process: bool = False, **kwargs: Any
args: Iterable[str] | None = None,
return_completed_process: bool = False,
**kwargs: Any,
) -> int | subprocess.CompletedProcess[str | bytes]:
"""Call the node executable with the given arguments.

Expand All @@ -111,24 +129,30 @@ def node(

@overload
def npm(
args: list[str] | None, return_completed_process: Literal[True], **kwargs: Any
args: Iterable[str] | None, return_completed_process: Literal[True], **kwargs: Any
) -> subprocess.CompletedProcess[str | bytes]: ...


@overload
def npm(
args: list[str] | None, return_completed_process: Literal[False], **kwargs: Any
args: Iterable[str] | None,
return_completed_process: Literal[False] = ...,
**kwargs: Any,
) -> int: ...


@overload
def npm(
args: list[str] | None = None, return_completed_process: bool = False, **kwargs: Any
args: Iterable[str] | None = None,
return_completed_process: bool = False,
**kwargs: Any,
) -> int | subprocess.CompletedProcess[str | bytes]: ...


def npm(
args: list[str] | None = None, return_completed_process: bool = False, **kwargs: Any
args: Iterable[str] | None = None,
return_completed_process: bool = False,
**kwargs: Any,
) -> int | subprocess.CompletedProcess[str | bytes]:
"""Call the npm executable with the given arguments.

Expand Down Expand Up @@ -159,24 +183,30 @@ def npm(

@overload
def npx(
args: list[str] | None, return_completed_process: Literal[True], **kwargs: Any
args: Iterable[str] | None, return_completed_process: Literal[True], **kwargs: Any
) -> subprocess.CompletedProcess[str | bytes]: ...


@overload
def npx(
args: list[str] | None, return_completed_process: Literal[False], **kwargs: Any
args: Iterable[str] | None,
return_completed_process: Literal[False] = ...,
**kwargs: Any,
) -> int: ...


@overload
def npx(
args: list[str] | None = None, return_completed_process: bool = False, **kwargs: Any
args: Iterable[str] | None = None,
return_completed_process: bool = False,
**kwargs: Any,
) -> int | subprocess.CompletedProcess[str | bytes]: ...


def npx(
args: list[str] | None = None, return_completed_process: bool = False, **kwargs: Any
args: Iterable[str] | None = None,
return_completed_process: bool = False,
**kwargs: Any,
) -> int | subprocess.CompletedProcess[str | bytes]:
"""Call the npx executable with the given arguments.

Expand Down