-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN: @doc - base.py & indexing.py #31970
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
Changes from all commits
06a5d9e
9a4abae
e580a96
ede988c
41a7552
6cd8082
1534dad
703f7a6
a1b0e0b
5077ab0
8ea6e1b
8e320ce
1ee2cf7
7bf242e
61e87af
224cec8
e01e108
48cfcda
20f96f2
76ed611
95a86ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -250,9 +250,11 @@ def doc(*args: Union[str, Callable], **kwargs: str) -> Callable[[F], F]: | |||||||||
A decorator take docstring templates, concatenate them and perform string | ||||||||||
substitution on it. | ||||||||||
|
||||||||||
This decorator is robust even if func.__doc__ is None. This decorator will | ||||||||||
add a variable "_docstr_template" to the wrapped function to save original | ||||||||||
docstring template for potential usage. | ||||||||||
This decorator will add a variable "_docstring_components" to the wrapped | ||||||||||
function to keep track the original docstring template for potential usage. | ||||||||||
If it should be consider as a template, it will be saved as a string. | ||||||||||
Otherwise, it will be saved as callable, and later user __doc__ and dedent | ||||||||||
to get docstring. | ||||||||||
|
||||||||||
Parameters | ||||||||||
---------- | ||||||||||
|
@@ -268,17 +270,28 @@ def decorator(func: F) -> F: | |||||||||
def wrapper(*args, **kwargs) -> Callable: | ||||||||||
return func(*args, **kwargs) | ||||||||||
|
||||||||||
templates = [func.__doc__ if func.__doc__ else ""] | ||||||||||
# collecting docstring and docstring templates | ||||||||||
docstring_components: List[Union[str, Callable]] = [] | ||||||||||
if func.__doc__: | ||||||||||
docstring_components.append(dedent(func.__doc__)) | ||||||||||
|
||||||||||
for arg in args: | ||||||||||
if isinstance(arg, str): | ||||||||||
templates.append(arg) | ||||||||||
elif hasattr(arg, "_docstr_template"): | ||||||||||
templates.append(arg._docstr_template) # type: ignore | ||||||||||
elif arg.__doc__: | ||||||||||
templates.append(arg.__doc__) | ||||||||||
|
||||||||||
wrapper._docstr_template = "".join(dedent(t) for t in templates) # type: ignore | ||||||||||
wrapper.__doc__ = wrapper._docstr_template.format(**kwargs) # type: ignore | ||||||||||
if hasattr(arg, "_docstring_components"): | ||||||||||
docstring_components.extend(arg._docstring_components) # type: ignore | ||||||||||
Comment on lines
+279
to
+280
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this could be a better fix for this one:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @datapythonista. I would consider this as two parts. One is to add type check for For remove
|
||||||||||
elif isinstance(arg, str) or arg.__doc__: | ||||||||||
docstring_components.append(arg) | ||||||||||
|
||||||||||
# formatting templates and concatenating docstring | ||||||||||
wrapper.__doc__ = "".join( | ||||||||||
[ | ||||||||||
arg.format(**kwargs) | ||||||||||
if isinstance(arg, str) | ||||||||||
else dedent(arg.__doc__ or "") | ||||||||||
for arg in docstring_components | ||||||||||
] | ||||||||||
) | ||||||||||
|
||||||||||
wrapper._docstring_components = docstring_components # type: ignore | ||||||||||
|
||||||||||
return cast(F, wrapper) | ||||||||||
|
||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment - this is very confusing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @WillAyd, I agree with you and @ simonjayhawkins here. It might be confusing. However, the original docstring is not extended from the base class. It seems like the original code obscures the problem because it does not explicitly indicate the source of the docstring. I try to keep it as it is but use
@doc
.It looks like we all agree this docstring template will confuse other developers, but do you feel needed to fix this issue in this PR? If so, what will be your suggestion? One option that comes in my mind will be using the docstring from the base class, and modify them to fit in this case. I was trying to avoid that because it will change the original docstring relations, and I am not sure if we did this on purpose.
Just to be clarified, I am very willing to make the additional change to solve this confusion. I just don't know what will be the best way of doing that. One more thing, I have a comment related to this. You might also be interested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a more suitable location for the docstring then? Importing the IndexOpsMixin here is strange
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I think this should be addressed in a follow up. It's here in
IndexOpsMixin
because that's where the_shared_docs
was. I think this PR is already too complex to make the change here. And if we change_shared_docs
before merging this, the conflict here will be quite annoying to fix. Does it make sense?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me, I feel this situation might be caused by they are sharing the same interface, but don't have a common ancestor.
If we have an interface declaration, I would say putting docstring there would be a good choice. However, Python as a dynamic programming language, don't have to declare the interface.
Now, I don't have a good solution in mind, but I would like to look for it and see if we can find somewhere that makes more sense.