Skip to content
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

Fix experimental decorator #1248

Merged
merged 27 commits into from Jun 5, 2020

Conversation

harupy
Copy link
Contributor

@harupy harupy commented May 16, 2020

Motivation

Fixes #1213

Description of the changes

Fix experimental to decorate a class method properly.

@harupy harupy marked this pull request as ready for review May 18, 2020 15:52
Copy link
Contributor

@crcrpar crcrpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for doing this and lettimg me know textwrap!

@harupy
Copy link
Contributor Author

harupy commented May 19, 2020

@crcrpar Thanks for the review! One question. We currently attach the experimental note to a function and class that do not have a docstring. For these functions and classes, I think just attaching a warning should be enough. What do you think?

@crcrpar
Copy link
Contributor

crcrpar commented May 19, 2020 via email

@harupy
Copy link
Contributor Author

harupy commented May 19, 2020

@harupy The implementation will be like this:

...

@functools.wraps(func)
def new_func(*args, **kwargs):
    warnings.warn(...)
    return func(*args, **kwargs)

if new_func.__doc__ is None:
    return new_func

new_func.__doc__ = ...

return new_func

@codecov-commenter
Copy link

codecov-commenter commented May 19, 2020

Codecov Report

Merging #1248 into master will increase coverage by 0.54%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1248      +/-   ##
==========================================
+ Coverage   86.50%   87.05%   +0.54%     
==========================================
  Files          94       94              
  Lines        7375     7950     +575     
==========================================
+ Hits         6380     6921     +541     
- Misses        995     1029      +34     
Impacted Files Coverage Δ
optuna/_experimental.py 100.00% <100.00%> (ø)
optuna/storages/base.py 63.00% <0.00%> (-4.92%) ⬇️
optuna/storages/in_memory.py 97.76% <0.00%> (+0.05%) ⬆️
optuna/storages/redis.py 93.15% <0.00%> (+0.08%) ⬆️
optuna/storages/rdb/storage.py 94.15% <0.00%> (+0.08%) ⬆️
optuna/storages/cached_storage.py 96.65% <0.00%> (+0.23%) ⬆️
optuna/integration/lightgbm_tuner/optimize.py 91.86% <0.00%> (+0.75%) ⬆️
optuna/storages/rdb/models.py 92.13% <0.00%> (+1.31%) ⬆️
optuna/study.py 95.58% <0.00%> (+1.97%) ⬆️
optuna/visualization/utils.py 80.00% <0.00%> (+2.22%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e23ef65...1b4faa1. Read the comment docs.

@crcrpar
Copy link
Contributor

crcrpar commented May 21, 2020

That sounds simple enough. It's up to you whether do that in this PR or a following PR. 😄

@harupy
Copy link
Contributor Author

harupy commented May 21, 2020

@crcrpar I'll open a follow-up.

tests/test_experimental.py Outdated Show resolved Hide resolved
@crcrpar
Copy link
Contributor

crcrpar commented May 26, 2020

@harupy Could you fix the checks failure?

@crcrpar crcrpar self-requested a review June 3, 2020 02:12
Copy link
Contributor

@crcrpar crcrpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being late. LGTM!

@harupy
Copy link
Contributor Author

harupy commented Jun 3, 2020

@crcrpar Thank you for the review :)

@harupy
Copy link
Contributor Author

harupy commented Jun 5, 2020

@toshihikoyanase @hvy Could you please review this PR?

Comment on lines +29 to +30
def _get_docstring_indent(docstring: str) -> str:
return docstring.split("\n")[-1] if "\n" in docstring else ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Question] This function seems to get the last line of the given docstring. Is it always corresponding to an indent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it always corresponding to an indent?

Not always. There are cases where this function does not work.

# the last line contains characters
def f():
    """summary

    detail"""
    pass

# the last line has a different indent level
def f():
    """summary

    detail
  """
    pass

def f():
    """summary

    detail
      """
    pass

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A not-so-strong drop by comment but I think it's okay assuming https://github.com/optuna/optuna/wiki/Coding-Style-Conventions#docstrings. We could add warnings in case some of these assumptions above are broken but it also sounds like overengineering.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your explanation. Although flake8 and black do not check such inconsistent indent levels, I think we can accept the current implementation as @hvy says.

@hvy hvy self-assigned this Jun 5, 2020
Copy link
Member

@hvy hvy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is quite a pain to debug but the tests mostly seem sufficient and I went through the decorated symbols and how they're rendered to ensure they looked as expected. Thanks as always, LGTM!

@hvy hvy added the document Documentation related. label Jun 5, 2020
Copy link
Member

@toshihikoyanase toshihikoyanase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for your contribution!

Comment on lines +29 to +30
def _get_docstring_indent(docstring: str) -> str:
return docstring.split("\n")[-1] if "\n" in docstring else ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your explanation. Although flake8 and black do not check such inconsistent indent levels, I think we can accept the current implementation as @hvy says.

@toshihikoyanase toshihikoyanase added this to the v2.0.0 milestone Jun 5, 2020
@toshihikoyanase toshihikoyanase merged commit 15a1878 into optuna:master Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
document Documentation related.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

experimental decorator adds extra indents to docs
5 participants