DocumentationAPI: Add padding - #4557
Conversation
jayvdb
left a comment
There was a problem hiding this comment.
I see you have not add padding for all other languages.
But you make padding mandatory.
So this would break all languages without a padding in their style?
There was a problem hiding this comment.
@jayvdb This answers your question :) . .coalang will have official standards defined.
By default top_padding and bottom_padding of DocComment are initialized with zero. If we don't have style defined. It will have default values. Also padding's major motive was if a developer doesn't wants to follow official standard and decides suppose I want to have 2 blank lines at the bottom of docstring. He will set those padding variables and it will be amended by the bear part.
There was a problem hiding this comment.
Why split this into to variables rather than store a tuple?
There was a problem hiding this comment.
using separate variables it becomes easily available at bear side. DocComment.docstyle_definition.top_padding/bottom_padding Also they are read as strings from the file(need int). I need to get separate values in the bear part anyhow. So why not split them in the first place.
There was a problem hiding this comment.
You can used NamedTuple to make it easier for them to be used.
The reason to keep them as a tuple is so that everywhere they are a pair, from style config to bear. consistency.
There was a problem hiding this comment.
Is it possible to provide a default value for this new arg, thereby avoiding breaking the API?
There was a problem hiding this comment.
let me see though. But I don't think that would cause any problem because load function provides an empty tuple if it finds nothing. Which I later break into the properties of top_padding and bottom_padding. which is taken care by #4557 (comment)
There was a problem hiding this comment.
yes this breaks the API. I tried to provide a default value. But the thing is load returns an empty tuple if it finds nothing which overwrites that default value. The best solution to providing default values through https://github.com/coala/coala/pull/4557/files#diff-bb503d77ea6d0498c9865cab08c904f4R64
There was a problem hiding this comment.
This is important I couldn't find any other way to do this :)
54b9fac to
84b0386
Compare
|
@jayvdb We can continue our discussion here.... As |
jayvdb
left a comment
There was a problem hiding this comment.
All of the examples seem to be using padding (1, 1).
I re-iterate what Niklas has said at coala/coala-bears#1943 (comment) , you need to be creating your own scenarios which test different valid values, even if there is no defined style with that scenario of values.
There was a problem hiding this comment.
this should be in method setUpClass or setUp .
There was a problem hiding this comment.
this (and the lines above) should be in method setUpClass or setUp
There was a problem hiding this comment.
nope; wrong per https://www.stack.nl/~dimitri/doxygen/manual/docblocks.html#pythonblocks
(and also this fixup must undo the bad changes in the previous patch to default.py : #4549 (review) )
No, you are wrong. On https://www.python.org/dev/peps/pep-0257/ , you can see it's status is "Active". It has not been replaced. It is maintained at https://github.com/python/peps/commits/master/pep-0257.txt
Again, wrong.
A design problem, for sure. |
c2158b4 to
f9560d7
Compare
There was a problem hiding this comment.
this blank line is also not acceptable.
There was a problem hiding this comment.
this blank line is also not acceptable.
There was a problem hiding this comment.
this blank line is also not acceptable.
There was a problem hiding this comment.
uhhh, I still don't understand. The padding is 0
There was a problem hiding this comment.
Why do we need getters for all those members?
There was a problem hiding this comment.
As everything we are fetching from .coalang is a standard. And we don't want anyone to set those up manually. Hence setting them as getters :)
PS- Even the previous things like markers, comment's signature....etc we are fetching from .coalang are introduced in DocstyleDefinition as getters.
There was a problem hiding this comment.
hm, ok... since Python doesn't have private members, the whole concept is a bit useless. But if you want to do it like that it's fine.
There was a problem hiding this comment.
There was a problem hiding this comment.
This is still unchanged and very inefficient. This method should be generator.
You have two options:
- Change
instantiate_paddingandinstantiate_docstring_typeto only process one docstring at a time, so this can become a generator. - move the functionality from
instantiate_paddingandinstantiate_docstring_typeintoextract_documentation_with_markersand useyield from
I prefer the second option.
There was a problem hiding this comment.
Yes I missed your previous comment we can do that...I see 👍
There was a problem hiding this comment.
you don't have to use get with a default value, that's why you're in a try/except block. And why are you casting this to a tuple? isn't it already an iterable?
There was a problem hiding this comment.
yes no need to use get now 🎉
yup this isn't an iterable. we need to cast into a tuple.
There was a problem hiding this comment.
when this reads function_padding from .coalang the values are just read as a strings.
suppose function_padding = 1, 0
This will be read as
docstyle_settings = {..., function_padding : '1, 0',...}
we cast then into a tuple ('1', '0') so they get as iterables and then we typecast them into integers.
There was a problem hiding this comment.
yup we can remove this I guess...
as now I will use docstyle_settings['function_padding'] instead of docstyle_settings.get()
which will throw a KeyError 👍
There was a problem hiding this comment.
this is what should throw the KeyError right?
This shouldn't be it, I was just showing an example
There was a problem hiding this comment.
This file contains unused source code.
Origin: PyUnusedCodeBear, Section: flakes.
The issue can be fixed by applying the following patch:
--- a/coalib/bearlib/languages/documentation/DocBaseClass.py
+++ b/coalib/bearlib/languages/documentation/DocBaseClass.py
@@ -1,4 +1,3 @@
-import re
from coalib.bearlib.languages.documentation.DocstyleDefinition import (
DocstyleDefinition)104815c to
a641681
Compare
NiklasMM
left a comment
There was a problem hiding this comment.
@damngamerz sorry this took so long. I'm beginning to like the overall design now 👍
Please have a look at my comments once more.
There was a problem hiding this comment.
Please mention the name of all these namedtuples in the docstring. Here for example A namedtuple "ClassPadding" consisting..., etc
There was a problem hiding this comment.
why is the default '', '' and not 0, 0?
There was a problem hiding this comment.
because 0, 0 will mean that official defined padding is 0, 0. So better leave the defaults to be '', ''
There was a problem hiding this comment.
please explain the -2 in a comment
There was a problem hiding this comment.
You could remove these two lines by replacing all occurrences of top_padding with doc.top_padding and dito for bottom_padding. There's no real need for a temporary variable.
There was a problem hiding this comment.
This comment is inaccurate, you're just compiling regexes here
There was a problem hiding this comment.
def some_function():
"""
documentation
"""
class myPrivateClass:
pass
This docstring would falsely be identified as a type class.
I suppose to mitigate this, you'll need to specify the position of the docstring in the coalang files, too.There was a problem hiding this comment.
I don't think so....we will require such a thing. Although I will add this in the test cases if it doesn't work we will have to think about the position.
There was a problem hiding this comment.
Yes this fails. We have two ways to solve this
First one is a tricky but will work, I think we can fix this by little prioritizing the algorithm
something like:
- we search the line closest to the docstring first. (whichever has least padding will be scanned by both the regexes first.)
- If paddings are found to be equal scanning the line before starting marker with regexes first(i.e. with both
functionandclass). Than last line will be scanned.
This will support the generic nature.
Second introducing docstring_type_position.
If we found its written top then we only scan top lines of the docstring with regexes or vice-versa.
There was a problem hiding this comment.
Im going with the second option looks much more future proof 👍
There was a problem hiding this comment.
introducing docstring_type_position is the correct solution. The other will not work, you'll only make it work for Python. Maybe docstring_position should suffice, I doubt that styles will position the docstring on different sides for different types.
There was a problem hiding this comment.
In your previous comment you said that docstyle_settings['class_padding'] is a string like "1, 0", if this is true, tuple("1, 0") will be ("1", ",", " ", "0"), which int will choke on. Rather use docstyle_settings['class_padding'].split(",")
Also I'm wondering why this isn't caught by tests.
There was a problem hiding this comment.
Hmm now even I m wondering the same. You are correct about tuple('1,0') will be ("1", ",", " ", "0") but what I figured out is docstyle_settings is a Setting object. Now when I do tuple(docstyle_settings['class_padding'].value) gives me ("1", ",", " ", "0") but when I only do tuple(docstyle_settings['class_padding']) gives me ('1', '0')(some magic 😛 I m guessing it has to do something with the Setting object). So I think let it be that way.
There was a problem hiding this comment.
uh no, please investigate
There was a problem hiding this comment.
I see why it's like that
coala/coalib/settings/Setting.py
Line 121 in 41e4752
Setting offers common data type conversions. It has list_delimeters for list/tuple conversion. That's why we are getting ('1', '0') while doing tuple(docstyle_settings['class_padding']) 🎉
There was a problem hiding this comment.
Wow, talk about overengineering.... anyway... it's ok then
There was a problem hiding this comment.
Why is this the desired behavior?
There was a problem hiding this comment.
we have such a case in DocStyleBear.
I don't wanna break the existing tests 😉
https://github.com/coala/coala-bears/blob/master/tests/documentation/test_files/DocumentationStyleBear/bad_file2.py.test#L21
There was a problem hiding this comment.
how is such a case handled by documentation extraction?
There was a problem hiding this comment.
What I mean is, if you parse and re-assemble this docstring, what will happen?
There was a problem hiding this comment.
oh yes! thats because....
The affected range is always taken from starting marker to the end marker(except in case of padding). DocumentationAPI doesn't care about whats after the end marker. Hence if its followed by inline comment...It's still is at the same position after the assembling.
aed5f19 to
eee38f9
Compare
|
@damngamerz one last thing: The commit message needs an update: |
2457968 to
a018577
Compare
|
@NiklasMM Updated commit message 👍 |
7f2f30c to
d53307c
Compare
|
ack d53307c |
Add `class_padding`, `function_padding` and `docstring_position` in DocstyleDefinition which are now acquired from `.coalang`. Add `top_padding` and `bottom_padding` which is automatically instantiated from DocumentationExtraction. Add `docstring_type` in DocumentationComment which will automatically determine the type of docstring from DocumentationExtraction. Add supporting test cases. Related to coala#4200
|
ack 070a19e |
|
@rultor merge |
Add
paddingin DocstyleDefinition whichare now acquired from
.coalang. Addtop_paddingandbottom_paddingwhichautomatically instantiate from
instantiate_paddingin DocBaseClass. Addsupporting test cases.
Related to #4200
For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!
Checklist
them.
individually. It is not sufficient to have "fixup commits" on your PR,
our bot will still report the issues for the previous commit.) You will
likely receive a lot of bot comments and build failures if coala does not
pass on every single commit!
After you submit your pull request, DO NOT click the 'Update Branch' button.
When asked for a rebase, consult coala.io/rebase
instead.
Please consider helping us by reviewing other peoples pull requests as well:
cobot mark wip <URL>to get it outof the review queue.
The more you review, the more your score will grow at coala.io and we will
review your PRs faster!