-
Notifications
You must be signed in to change notification settings - Fork 0
Description
I happened to find this project after realizing implementing something similar myself was a bit more involved than I wanted, and it seems like a really novel, neat way to do it!
Experimenting around for a bit, I've started to realize I'm either not doing it right or something else is going on. An example:
# respackr/generate/main.py
from argparsedecorator.annotations import Exactly1, Option
from termaconfig import ConfigValidationError, TermaConfig
from terminaltables3 import DoubleTable
from respackr import cli
@cli.command()
def generate(config_path: Option | Exactly1[str] = ["respackr.toml"]):
"""Generates zipped resourcepacks, ready to publish or use in-game"""
spec_path = "respackr/spec.toml"
global config
try:
config = TermaConfig(config_path[0], spec_path, tabletype=DoubleTable, logging=False)
except ConfigValidationError:
print()
print("Errors are present in configuration. Exiting...")
exit()
print("Testing config:", config["pack"])Expression of type "list[str]" cannot be assigned to parameter of type "Option | Exactly1[str]" is what Pyright returns for that particular annotation, though as far as I can see from the docs, that's how it should be done. Also, Exactly1 returns a list when the arg is specified, but if the default is a simple string (not one-item list) it returns a string too. I guess it makes sense for consistency with the more than one ExactlyX options, though, pyright also complains about "__getitem__" method not defined on type "Exactly1[str]" in that case as well.
Another semantics issue is that the intended way to use argparseDecorator seems to be to recursively import, which makes type checkers complain quite a bit. For the annotation classes, there are two different import paths between annotations and parsernode, assuming the former is technically more correct. I imaging it's inconsequential where they're imported from, but it seems like it should be a bit more resolute what's correct there?
(edited: somehow pressed submit before I finished the issue)