Skip to content

Commit

Permalink
fix(compat): typer list type errors on py3.8
Browse files Browse the repository at this point in the history
Signed-off-by: Braden Mars <bradenmars@bradenmars.me>
  • Loading branch information
BradenM committed Mar 27, 2023
1 parent 5517fee commit 3483302
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
20 changes: 11 additions & 9 deletions micropy/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from enum import Enum
from pathlib import Path
from typing import Optional, cast
from typing import List, Optional, cast

import micropy.exceptions as exc
import questionary as prompt
Expand Down Expand Up @@ -49,12 +49,14 @@ def main_callback(ctx: typer.Context):
log.info("You can update via: $[pip install --upgrade micropy-cli]\n")


TemplateEnum = Enum("TemplateEnum", {t: t for t in modules.TemplatesModule.TEMPLATES}, type=str)
TemplateEnum = Enum(
"TemplateEnum", {t: t for t in list(modules.TemplatesModule.TEMPLATES.keys())}, type=str
)


def template_callback(
ctx: typer.Context, value: Optional[list[TemplateEnum]]
) -> Optional[list[TemplateEnum]]:
ctx: typer.Context, value: Optional[List[TemplateEnum]]
) -> Optional[List[TemplateEnum]]:
if ctx.resilient_parsing:
return
if not value:
Expand Down Expand Up @@ -91,7 +93,7 @@ def name_callback(ctx: typer.Context, value: Optional[str]) -> Optional[str]:
return value


def stubs_callback(ctx: typer.Context, value: Optional[list[str]]) -> Optional[list[Stub]]:
def stubs_callback(ctx: typer.Context, value: Optional[List[str]]) -> Optional[List[Stub]]:
if ctx.resilient_parsing:
return
mpy = ctx.ensure_object(MicroPy)
Expand Down Expand Up @@ -138,15 +140,15 @@ def main_init(
show_default=False,
callback=name_callback,
),
template: Optional[list[TemplateEnum]] = typer.Option(
template: Optional[List[TemplateEnum]] = typer.Option(
None,
"--template",
"-t",
help="Templates to generate for project. Can be specified multiple times. Skips interactive prompt.",
show_default=False,
callback=template_callback,
),
stubs: Optional[list[str]] = typer.Option(
stubs: Optional[List[str]] = typer.Option(
None,
"--stubs",
"-s",
Expand Down Expand Up @@ -208,7 +210,7 @@ def install_local_callback(ctx: typer.Context, value: Optional[Path]) -> Optiona
raise typer.Exit()


def install_project_callback(ctx: typer.Context, value: Optional[list[str]]) -> Optional[list[str]]:
def install_project_callback(ctx: typer.Context, value: Optional[List[str]]) -> Optional[List[str]]:
"""Handle project requirements install."""
if ctx.resilient_parsing:
return
Expand All @@ -233,7 +235,7 @@ def install_project_callback(ctx: typer.Context, value: Optional[list[str]]) ->
@app.command(name="install")
def main_install(
ctx: typer.Context,
packages: Optional[list[str]] = typer.Argument(
packages: Optional[List[str]] = typer.Argument(
None, help="Packages to install.", callback=install_project_callback
),
dev: bool = typer.Option(
Expand Down
16 changes: 9 additions & 7 deletions micropy/app/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import tempfile
from enum import Enum
from pathlib import Path
from typing import Optional, Type
from typing import List, Optional, Type

import micropy.exceptions as exc
import typer
Expand Down Expand Up @@ -62,7 +62,7 @@ def __new__(cls, value: str, backend: Type[MetaPyDeviceBackend]):
return obj


def changeset_callback(value: Optional[list[str]]) -> Optional[ListChangeSet]:
def create_changeset(value: Optional[List[str]]) -> Optional[ListChangeSet]:
if value is None:
return value
return ListChangeSet.from_strings(add=value)
Expand All @@ -76,9 +76,11 @@ def stubs_create(
variant: stub_board.CreateStubsVariant = typer.Option(
stub_board.CreateStubsVariant.BASE, "-v", "--variant", help="Create Stubs variant."
),
module: Optional[list[str]] = typer.Option(None, "-m", "--module", help="Modules to add."),
exclude: Optional[list[str]] = typer.Option(
None, "-e", "--exclude", help="Modules to exclude."
module: Optional[List[str]] = typer.Option(
None, "-m", "--module", help="Modules to add.", rich_help_panel="Stubs"
),
exclude: Optional[List[str]] = typer.Option(
None, "-e", "--exclude", help="Modules to exclude.", rich_help_panel="Stubs"
),
):
"""Create stubs from a micropython-enabled device."""
Expand Down Expand Up @@ -108,8 +110,8 @@ def _get_desc(name: str, cfg: dict):
log.success("Connected!")
create_stubs = prepare_create_stubs(
variant=variant,
modules_set=changeset_callback(module),
exclude_set=changeset_callback(exclude),
modules_set=create_changeset(module),
exclude_set=create_changeset(exclude),
)
log.info("Executing stubber on pyboard...")
try:
Expand Down

0 comments on commit 3483302

Please sign in to comment.