Comments (9)
I was just having this conversation with @halst .
I second the idea. If sys is called within the method and not in the method header I can test like a user would call it...
https://github.com/barberj/ForGit/blob/5aedc5afeb3112796cb55f3e5f571d1c4e580938/test_forgit.py (Specifically look at TestCLI)
Above is an example of the tests I'm able to achieve using my forked docopt with argv defaulted to none.
from docopt.
Why not pass sys.argv[1:]
explicitly in case something modifies sys.argv
. The benefits of this change are not clear to me.
from docopt.
I'm indifferent now (Line 180 https://github.com/barberj/ForGit/blob/master/forgit.py). I have been doing just as you suggested. It was just frustrating initially when i was trying to write test cases.
from docopt.
The current behaviour is surprising and unexpected. To quote https://en.wikipedia.org/wiki/Principle_of_least_astonishment:
"People are part of the system. The design should match the user's experience, expectations, and mental models."
If you know about the current behaviour, it may be easy to workaround. But that's not a good reason to keep it and I can't think of other reasons to keep the current behaviour...
btw. when can we expect the next release?
from docopt.
Next release is planned this year.
Let me be devil's advocate for a moment:
What is so astonishing/unexpected when docopt parses the exact same options that were passed from command-line, not those obtained by some side-effect?
from docopt.
docopt doesn't parse the options that were passed from command-line. it parses the value of sys.argv at import time.
given the fact that some people will mock with sys.argv, docopt's behaviour is now also dependent on the import order.
and if you're one of those, you'll have to look around a bit in order to explain docopts behaviour. it isn't obvious that it's parsing something different from the value of sys.argv at call time.
python's behaviour of evaluating default arguments at import time is also a well known gotcha and unexpected to some people (see http://stackoverflow.com/questions/530530/python-2-x-gotchas-and-landmines). you're relying on that exact feature in order to implement more unexpected behaviour.
speaking of side-effects I think I can always just reload(docopt) in case I need to call into a program's main function :)
from docopt.
I'm sold. This will break some people's code, but I'm implementing that for purity sake. Import order should not influence docopt behavior.
from docopt.
Reading sys.argv at runtime also makes it possible to use docopt interactively with ipython's run command.
from docopt.
As of 0.6.0, argv
is None
by default, and docopt
evaluates sys.argv[1:]
when called. Thanks everyone for the fruitful discussion.
from docopt.
Related Issues (20)
- Is docopt / docopt itself still being maintained? HOT 1
- Please upload a wheel package to pypi HOT 6
- get_docopts.sh fails on M1 Monterey 12.6
- Short options in docopt not returning correct values HOT 1
- [FeatureRequest] Allow hash comments in docstring ? HOT 4
- Make new release HOT 3
- try.docopt.org is offline HOT 1
- Dart port? HOT 1
- Make docopt exceptions public
- How to call "python -m mypackage [options]" HOT 1
- Is there some docopt validator? HOT 1
- Why cannot docopt parse args? HOT 3
- Please share wheel file on pypi HOT 1
- Docopt AssertionError
- Having same issues as #516
- Unix-style vs. Windows-style options HOT 2
- Abandonware status of docopt HOT 7
- Why is the docopt website not served through HTTPS?
- Any good reason not to use GitHub releases? HOT 1
- how to implement number argument? 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 docopt.