If you want to know what a stenotype expression evaluates to, adding it to a source file and printing that variable's __annotation__ is a cumbersome workflow. We should have a CLI that works like this once stenotype was installed:
$ stenotype "bool or ?int"
typing.Union[bool, typing.Optional[int]]
$ stenotype "some invalid stenotype expression"
stenotype.ParseError: Failed in some way, maybe some useful info here: ...
It would just call the backend, skip any assertion steps (which shouldn't be part of the backend anyway), and try to parse the expression into a standard type annotation using the typing module and its syntax.
multiple arguments are interpreted as multiple lines following each other, useful for TypeVars that need to be set up
there should be an optional argument like -m <path to file> that will load the file in order to look up class names that might be referenced in the stenotype expression
other possible flags, that should be considered for the implementation already but are not necessary yet:
--shorten or -s, inverts the parser and turns a verbose type annotation into a short one
--checks or -c disables the check-skipping step, i.e. the code will be written exactly as it would be in the source file, and something like var: "?bool" # stenotype: no would not be translated. This would be useful to troubleshoot the is-this-recognized-as-stenotype rules.
[x] add stub backend module that pretends to be working already
[x] write cli module that runs the commands as specified
[x] write console_script section that installs the cli
If you want to test the cli, checkout the branch from #18 and run poetry install again (new entrypoints need to be explicitly installed). After that, stenotype --help should work.
If you want to know what a
stenotype
expression evaluates to, adding it to a source file and printing that variable's__annotation__
is a cumbersome workflow. We should have a CLI that works like this oncestenotype
was installed:It would just call the backend, skip any assertion steps (which shouldn't be part of the backend anyway), and try to parse the expression into a standard type annotation using the
typing
module and its syntax.-m <path to file>
that will load the file in order to look up class names that might be referenced in thestenotype
expression--shorten
or-s
, inverts the parser and turns a verbose type annotation into a short one--checks
or-c
disables the check-skipping step, i.e. the code will be written exactly as it would be in the source file, and something likevar: "?bool" # stenotype: no
would not be translated. This would be useful to troubleshoot the is-this-recognized-as-stenotype rules.console_script
section that installs the cli