BayesianOptimization icon indicating copy to clipboard operation
BayesianOptimization copied to clipboard

Fix add typehint without generic

Open phi-friday opened this issue 1 year ago • 1 comments

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.

phi-friday avatar Jul 25 '24 14:07 phi-friday

@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.

till-m avatar Aug 09 '24 17:08 till-m

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 :warning:
bayes_opt/target_space.py 95.00% 2 Missing :warning:
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     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Sep 08 '24 08:09 codecov[bot]

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?

till-m avatar Sep 08 '24 11:09 till-m

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. https://github.com/sphinx-doc/sphinx/issues/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.

phi-friday avatar Sep 08 '24 12:09 phi-friday

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.

till-m avatar Sep 08 '24 13:09 till-m

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).

phi-friday avatar Sep 08 '24 14:09 phi-friday

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.

till-m avatar Sep 11 '24 16:09 till-m

Thanks for the PR!

till-m avatar Sep 19 '24 18:09 till-m