Lucretiel / autocommand

Autocommand turns a python function into a CLI program
GNU Lesser General Public License v3.0
52 stars 8 forks source link

PEP 563 compatiblity #35

Open bswck opened 7 months ago

bswck commented 7 months ago

Current string-check argument parsing is pretty naive and doesn't work for postponed annotations. https://peps.python.org/pep-0563/

bswck commented 7 months ago

Example:

Having

# foo.py
from autocommand import autocommand

@autocommand(__name__)
def main(arg: int):
    pass

the python -m foo m command correctly reports an error:

usage: foo.py [-h] arg
foo.py: error: argument arg: invalid int value: 'm'

However, adding from __future__ import annotations on top of the module breaks this and skips validation:

Having

# foo-ann.py
from __future__ import annotations
from autocommand import autocommand

@autocommand(__name__)
def main(arg: int):
    pass

the python -m foo-ann m command works just fine.

bswck commented 7 months ago

[!Note] It was a known issue: https://github.com/Lucretiel/autocommand/blob/acff23e565ae90c44cb2d10ecdd729d25949e2b7/src/autocommand/autoparse.py#L60-L61

bswck commented 7 months ago

Related to https://github.com/Lucretiel/autocommand/issues/30.

Lucretiel commented 7 months ago

I'm confused by that PEP; this is just a major breaking change being shipped to a future minor release of Python?

Lucretiel commented 7 months ago

PEP 563 appears to have been superseded, due to backwards compatibility issues, so I'm closing this for now. Feel free to re-open if PEP is restored.

bswck commented 7 months ago

PEP 563 appears to have been superseded, due to backwards compatibility issues, so I'm closing this for now. Feel free to re-open if PEP is restored.

Strong -1 on this one. It indeed has been superseded by PEP 649, but PEP 649 is to come in Python 3.13 that hasn't yet even been released. A correct conclusion would be that PEP 563 would no longer be supported by October 2028. Until 2028, please consider supporting PEP 563, because

@Lucretiel, could you please reopen? I'm not able to do it myself.