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 add typehint without generic #507

Merged

Conversation

phi-friday
Copy link
Contributor

related: #493

I didn't use the generic and added type hints using primitive types in most cases.

Therefore, I ignored some types with Any.
I also ignored some errors from the static type checker.

Hopefully, this will provide a better IDE experience than before.

@till-m
Copy link
Member

till-m commented Aug 9, 2024

@phi-friday, I haven't forgotten your PRs. I will review once #509 and #510 are merged to prevent any conflict on the gh-pages branch.

@phi-friday phi-friday force-pushed the fix-add-typehint-without-typevar branch from 8b3e868 to 0a694e8 Compare September 8, 2024 08:48
Copy link

codecov bot commented Sep 8, 2024

Codecov Report

Attention: Patch coverage is 97.01493% with 4 lines in your changes missing coverage. Please review.

Project coverage is 95.89%. Comparing base (aed6a25) to head (c9ca71e).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
bayes_opt/constraint.py 84.61% 2 Missing ⚠️
bayes_opt/target_space.py 95.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #507      +/-   ##
==========================================
- Coverage   96.19%   95.89%   -0.30%     
==========================================
  Files          10       11       +1     
  Lines         867      877      +10     
==========================================
+ Hits          834      841       +7     
- Misses         33       36       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@phi-friday phi-friday force-pushed the fix-add-typehint-without-typevar branch from 5d3f145 to b340e6c Compare September 8, 2024 09:08
@phi-friday phi-friday force-pushed the fix-add-typehint-without-typevar branch from b340e6c to 84e2831 Compare September 8, 2024 09:19
Copy link
Member

@till-m till-m left a comment

Choose a reason for hiding this comment

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

I'm probably not too qualified to judge this PR. I left some comments where I noticed specific things, but overall it looks good to me :)

bayes_opt/acquisition.py Outdated Show resolved Hide resolved
bayes_opt/bayesian_optimization.py Outdated Show resolved Hide resolved
bayes_opt/constraint.py Show resolved Hide resolved
@till-m
Copy link
Member

till-m commented Sep 8, 2024

I noticed, that since TYPE_CHECKING is false during the build, it breaks links to other documentations that were generated with intersphinx. This even includes imports made outside of the if TYPE_CHECKING: block, e.g. the GaussianProcessRegressor of acquisition.html#bayes_opt.acquisition.AcquisitionFunction.suggest. Do you know if it's possible to set this variable to True when building the docs somehow?

@phi-friday
Copy link
Contributor Author

I noticed, that since TYPE_CHECKING is false during the build, it breaks links to other documentations that were generated with intersphinx. This even includes imports made outside of the if TYPE_CHECKING: block, e.g. the GaussianProcessRegressor of acquisition.html#bayes_opt.acquisition.AcquisitionFunction.suggest. Do you know if it's possible to set this variable to True when building the docs somehow?

As far as I know, this is not possible.
(Even if it were possible, I'd be cautious about it because it could cause circular reference errors).

Let's see what we can do.
This seems to be an issue with using the autodoc ext. sphinx-doc/sphinx#9813

However, the link was not created on np.random.RandomState, np.ndarray in the master branch either.
I'll have to check if there's a possible other issue.

@till-m
Copy link
Member

till-m commented Sep 8, 2024

However, the link was not created on np.random.RandomState, np.ndarray in the master branch either.

I've seen it happen with types in docstrings, but not with type hint types (?). But yes, it does seem to behave non-reliably there, though if there are no docstring types, the docs generator will take them from the hints -- so at some point in the future we could remove type specifications from docstrings and just work with the typhints.

@phi-friday
Copy link
Contributor Author

phi-friday commented Sep 8, 2024

However, the link was not created on np.random.RandomState, np.ndarray in the master branch either.

I've seen it happen with types in docstrings, but not with type hint types (?). But yes, it does seem to behave non-reliably there, though if there are no docstring types, the docs generator will take them from the hints -- so at some point in the future we could remove type specifications from docstrings and just work with the typhints.

I fixed some issues using sphinx-autodoc-typehints.
(There are still places where it doesn't).
I expect links to be created where they were previously created.
Also fixed some previously unlinked types (like np.ndarray).

@till-m
Copy link
Member

till-m commented Sep 11, 2024

Hey @phi-friday,

after thinking about it, the goal for this PR (to me) is to add the types, as you did, and ideally have the signatures as rendered in the docs linked and looking pretty. Anything else is out of scope and should not hold up the merging of this PR, i.e. let's worry about the docstrings later. I don't think we need to overdo it.

Long-term, I would ideally like to have all docstrings without types and let sphinx render them based on the type signature.

Copy link
Member

@till-m till-m left a comment

Choose a reason for hiding this comment

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

I added another set of comments. If I understand correctly, you mainly relied on the docstrings to make the type annotations. Since they were sometimes a bit carelessly written, I will take some time and thoroughly check that the type hints are correct when I get a chance. Apologies for this PR taking so long.

bayes_opt/target_space.py Outdated Show resolved Hide resolved
bayes_opt/target_space.py Outdated Show resolved Hide resolved
bayes_opt/target_space.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
docsrc/conf.py Outdated Show resolved Hide resolved
docsrc/conf.py Show resolved Hide resolved
bayes_opt/acquisition.py Outdated Show resolved Hide resolved
bayes_opt/acquisition.py Outdated Show resolved Hide resolved
bayes_opt/acquisition.py Outdated Show resolved Hide resolved
@till-m till-m merged commit a4d2d07 into bayesian-optimization:master Sep 19, 2024
11 checks passed
@till-m
Copy link
Member

till-m commented Sep 19, 2024

Thanks for the PR!

@phi-friday phi-friday deleted the fix-add-typehint-without-typevar branch September 20, 2024 02:51
@phi-friday phi-friday mentioned this pull request Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants