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

Allow to dispatch getting documentation on objects. #13975

Merged
merged 1 commit into from Mar 30, 2023

Conversation

Carreau
Copy link
Member

@Carreau Carreau commented Mar 14, 2023

Base for #13860, so that object can be queried for documentation on their fields/properties.

Typically this allows the following, to extend the doc documentation when requesting information on a field.

class DictLike:
    def __getitem__(self, k):
        if k.startswith('f'):
            return "documentation for k"
        else:
            raise KeyError

class Bar:
    __custom_documentations__ = DictLike()

    faz = 1


    @property
    def foo(self):
        return 1
b = Bar()
b.faz?

@Carreau Carreau force-pushed the hook-docstring branch 2 times, most recently from 765ef0c to b78041d Compare March 24, 2023 08:01
@Carreau Carreau marked this pull request as ready for review March 24, 2023 09:24
@Carreau Carreau changed the title Draft: allow to dispatch getting documentation on objects. Allow to dispatch getting documentation on objects. Mar 30, 2023
Base for ipython#13860, so that object can be queried for documentation on
their fields/properties.

Typically this allows the following, to extend the doc documentation
when requesting information on a field.

    In [1]: class DictLike:
       ...:     def __getitem__(self, k):
       ...:         if k.startswith('f'):
       ...:             return "documentation for k"
       ...:         else:
       ...:             raise KeyError
       ...:
       ...: class Bar:
       ...:     __custom_documentations__ = DictLike()
       ...:
       ...:     faz = 1
       ...:
       ...:
       ...:     @Property
       ...:     def foo(self):
       ...:         return 1
       ...: b = Bar()

    In [2]: b.faz?
@Carreau Carreau added this to the 8.12 milestone Mar 30, 2023
@Carreau Carreau merged commit d52bf62 into ipython:main Mar 30, 2023
22 checks passed
@krassowski
Copy link
Member

I guess I am late to notice this, but should we also allow __custom_documentation__ (no s) since in common usage documentation is uncountable? Any native speakers with an opinion?

Carreau added a commit that referenced this pull request Apr 11, 2023
For example, without this change, doing `df.merge?` on a pandas
DataFrame currently fails, because `df.__bool__()` raises an exception.

I'm not sure the best way to add a test, and at a glance I didn't see
any issue for this yet.

This regression was introduced in #13975 and version 8.12.0. CC @Carreau
@Carreau
Copy link
Member Author

Carreau commented Apr 17, 2023

I guess I am late to notice this, but should we also allow __custom_documentation__ (no s) since in common usage documentation is uncountable? Any native speakers with an opinion?

Sorry I havent' responded to that.

For me __custom_documentation__ would be a single string not a container of string.

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.

None yet

2 participants