Comments (7)
This is fixed in v2.3.1. If you believe it's not fully fixed we can re-open the issue. Thanks!
from cyclopts.
this is better now but still not fixed completly
this is small simple argparse to show the expected output from list and different input outputs
import argparse
parser=argparse.ArgumentParser()
parser.add_argument("--items",action='append')
parser.add_argument("--stuff",action='store')
if __name__ == "__main__":
ns=parser.parse_args()
print(ns)
and some example input output runs
> ./cli.py --item a --item b --item
usage: cli.py [-h] [--items ITEMS] [--stuff STUFF]
cli.py: error: argument --items: expected one argument
orhayat:~ via 🐹 v1.21.4 via 🐍 v3.10.12
> ./cli.py --item a --item b --item c
Namespace(items=['a', 'b', 'c'], stuff=None)
orhayat:~ via 🐹 v1.21.4 via 🐍 v3.10.12
> ./cli.py --item a --item b --item c --stuff=test
Namespace(items=['a', 'b', 'c'], stuff='test')
orhayat:~ via 🐹 v1.21.4 via 🐍 v3.10.12
> ./cli.py --item a --item b --item=c --stuff=test
Namespace(items=['a', 'b', 'c'], stuff='test')
orhayat:~ via 🐹 v1.21.4 via 🐍 v3.10.12
> ./cli.py --item a --item b --item= --stuff=test
Namespace(items=['a', 'b', ''], stuff='test')
orhayat:~ via 🐹 v1.21.4 via 🐍 v3.10.12
> ./cli.py --item a --item b --item= c --stuff=test
usage: cli.py [-h] [--items ITEMS] [--stuff STUFF]
cli.py: error: unrecognized arguments: c
and now small cyclopts command that send list of tuples
import cyclopts
cli=cyclopts.App()
@cli.command
def cmd(items:list[tuple[str,str]]=None,stuff:str=None):
print(f"items:{items},stuff:{stuff}")
if __name__ == "__main__":
cli()
version:
pip3 list |grep cyclopts
cyclopts 2.3.1
import cyclopts
cli=cyclopts.App()
@cli.command
def cmd(items:list[tuple[str,str]]=None,stuff:str=None):
print(f"items:{items},stuff:{stuff}")
if __name__ == "__main__":
cli()
> ./cli.py cmd --items a b --stuff g
items:[('a', 'b')],stuff:g # ok
orhayat:~ via 🐹 v1.21.4 via 🐍 v3.10.12
> ./cli.py cmd --items a --stuff g
items:[],stuff:g # got single token and skipped it because didnt got other one
orhayat:~ via 🐹 v1.21.4 via 🐍 v3.10.12
> ./cli.py cmd --items= a --stuff g
items:[('', 'a')],stuff:g # similar behaviour to argparse
orhayat:~ via 🐹 v1.21.4 via 🐍 v3.10.12
> ./cli.py cmd --items= a b --stuff g
items:[('', 'a')],stuff:g # b token was skipped
from cyclopts.
other example on list of strings
even if u replace the type of list of tuples to list of string it dont behave as expected
```python3
import cyclopts
cli=cyclopts.App()
@cli.command
def cmd(items:list[str]=None,stuff:str=None):
print(f"items:{items},stuff:{stuff}")
if __name__ == "__main__":
cli()
./cli.py cmd --items a b
items:['a', 'b'],stuff:None #ok
orhayat:~ via 🐹 v1.21.4 via 🐍 v3.10.12
> ./cli.py cmd --items a b --stuff g
items:['a', 'b'],stuff:g #ok
./cli.py cmd --items=a b --stuff g
items:['a', 'b'],stuff:g # ok
./cli.py cmd --items=a # error but should be [a],None....
╭─ Error ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Command "cmd" parameter "--items,--empty-items" requires an argument. │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
./cli.py cmd --items= #error idk what expected (work on argparse but w/e) but anyway look on the next example
╭─ Error ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Command "cmd" parameter "--items,--empty-items" requires an argument. │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
./cli.py cmd --items= a
items:['', 'a'],stuff:None
from cyclopts.
thanks for the thorough report! I'll work on this tonight.
from cyclopts.
@OrHayat please checkout #109, I believe it should resolve all the issues.
IMHO specifying stuff like --items= a
should either
- result in
['', 'a']
. or: - result in an error saying that you cannot have a space immediately following an
=
, as this behavior is probably not desirable and could cause confusion.
If you agree with (2), I could add that check.
So similarly, cmd --items= a b --stuff g
interprets 3 tokens for --items
: '', 'a', 'b'
, and so it now appropiately raises an exception that the 3 arguments cannot be divisible by two arguments per element.
from cyclopts.
the side branch seems to work as expected.
i think 1 is ok behaviour it the same behaviour as argparse and it also the same behaviour in typer.
from cyclopts.
this is fixed in v2.3.2. I think we may revisit the --option=
discussion in the future, but I will close this issue for now (but we can certainly re-open if/when you find more bugs!).
from cyclopts.
Related Issues (20)
- [Feature Request] Completion? HOT 6
- App() console parameter HOT 2
- integration with https://pypi.org/project/typed-settings/ HOT 2
- [BUG]: bad error report because of assetion error when there is UnusedCliTokensError HOT 2
- [BUG] list of tuple of single item is parsed but take only the first character of each token get parsed HOT 2
- Misleading error message when flag name has an underscore HOT 2
- the help format parsing is not consistent HOT 2
- Misc likely (rare) typing bugs HOT 1
- Use of the meta application results in a double help display HOT 5
- Automatic conversion from underscore to hyphen HOT 3
- Prompt for missing required parameters HOT 6
- Newlines should not be present in descriptions that span multiple lines HOT 5
- [Feature Request] Add auto_env_var_prefix HOT 19
- Importing cyclopts fails if there is a file called "tokenize.py" in the project which imports cyclopts HOT 1
- [feature request]: automatic markdown documentation generation HOT 3
- Support rich markup in version strings HOT 2
- Support 'type statement' HOT 4
- Single-character option name HOT 2
- Loosen python version requirement from `>=3.8,<4.0` to `>=3.8` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cyclopts.