New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docopt.__doc__ docstring #81
Comments
It is extremely silly that
|
It's a different scope of documentation again, I think. A module docstring's purpose is to provide a brief overview of the module and its functions, not tutorials and installation instructions. Besides, it'd break For #76, ordinary hash comments at the beginning of the file should do. |
There is a subtle issue with docopt.docopt doctring: it currently plays badly with doctests. This is not an issue for docopt itself because it doesn't use doctests. But if a project which uses doctests decides to embed docopt.py into the distribution (instead of requiring users to install it from pypi), then doctests for this project may start to fail because "vendorized" docopt is not available as "from docopt import docopt" (esp. under Python 3 where relative imports must be explicit). So I think the docstring for docopt.docopt shouldn't use "from docopt import docopt" because this is incorrect when docopt is "vendorized", and "vendorizing" is suggested in README ("Alternatively, you can just drop docopt.py file into your project--it is self-contained.") Maybe just remove the example? |
The example is not a valid doctest anyway because
is not a valid doctest syntax (... should be used for indentation). If you want to keep the example, then this would make it valid doctest even if vendorized:
|
@kmike, thanks for pointing this out. I will integrate your patch later this day. However, I really dislike having the doctest flag ( |
Yes, the doctest syntax is quite ugly, and we're lucky that there is only a single line that have to be skipped. Alternatively, "import" part may be described in a free-text form, but this is also going to be quite ugly. The root issue here (IMHO) is that "docopt" is ambiguous: it can mean both module and function. I always (well, all 3 or 4 times) tend to do "import docopt", then copy-paste an example from README below the Imagine the function is named 'parse', not 'docopt'. Then the example in README would be
(note how it saves some keystrokes in this example; most probably, both "import" statement and "docopt.parse(..)" call would occur only once in a source code so this should save keystrokes in real projects as well). With Don't get me wrong, I think that "docopt.docopt" vs "docopt.parse" thing is a minor question which is not very important, and that docopt is wonderful :) |
@kmike, I understand you well. Too bad Python does not allow modules to be callable. I would imagine that if module had a import docopt
args = docopt(__doc__) I tracked down, why module cannot be callable, and here is the answer: http://svn.python.org/projects/python/trunk/Objects/object.c But it is so for no good reason apparently. |
I have a proven track record of abusing module subclasses (for overcoming fabric limitations, in https://github.com/kmike/fabric-taskset), so here is a hack using module subclass:
UPD: getattr -> getattribute |
@kmike, I didn't know that is possible. Thanks for suggestion. I made a I'm still not sure if it is a good idea or not. @docopt/docopt anyone? On one hand it avoids the |
@halst, just for the record: I think that |
I'd really rather not clutter docopt.py up with an ugly hack just to offer some syntactic sugar. AFAIK it's pretty common in the Python world for modules that really only export one function or class to just share their name with the function/class, and I think we should stick with that, confusing as it may be. If it's really a problem, |
Agree, callable module is an ugly hack. But what about using a callable module in order to give a better error-message? Along the lines of: >>> import docopt
>>> args = docopt('usage: prog', '')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable, use 'from docopt import docopt' instead |
I don't really like that either; it's an awful lot of weird code just to add one clause to the error message. (I don't like the Dict class for much the same reason, but that's another can of worms I suppose.) People not understanding what "'module' object is not callable" means isn't the problem anyway, it's that they forget to import the function proper the first time around. |
Agree, callable module is a stupid idea (at least in Python). Docstring is now doctestable, and I set tox/travis to doctest it only on 2.7, which tests validity of documentation without needing to deal with Python 2 vs 3 differences. |
Does anyone think it's a good I dea to read
docopt.__doc__
fromREADME.rst
file? I can't see people doing similar things, there should be a reason.I'm thinking of adding the following to
docopt.py
:The text was updated successfully, but these errors were encountered: