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

Inherited members showing up inappropriately #102

Closed
analog-cbarber opened this issue Aug 25, 2023 · 5 comments
Closed

Inherited members showing up inappropriately #102

analog-cbarber opened this issue Aug 25, 2023 · 5 comments

Comments

@analog-cbarber
Copy link

Using mkdocstrings-python 1.5.2 w/ griffe 0.35, we noticed that suddenly inherited members
started showing up in our API docs although we did not ask for them. They show up even
when explicitly turned off.

Our code is internal, so I cannot share it, but I did some poking into do_filter_objects
and found that the offending members are aliases whose target is inherited. This hack
in do_filter_objects appears to mimic the old behavior:

    if members_list is True:
        # Return all pre-selected members.
        return objects

    # HACK - remove inherited aliases
    from griffe.dataclasses import Alias
    for i in reversed(range(len(objects))):
        obj = objects[i]
        if isinstance(obj,Alias):
            assert not obj.inherited
            if obj.target.inherited:
                objects.pop(i)

Hope that is enough to go on....

@analog-cbarber
Copy link
Author

I find that still leaves some broken cross references for some class methods that come from another library.

If I go into griffe and modify Alias.members to set the inherited property from the target:

    @cached_property
    def members(self) -> dict[str, Object | Alias]:  # noqa: D102
        final_target = self.final_target
        return {name: Alias(name, target=member, parent=self, inherited=final_target.inherited) for name, member in final_target.members.items()}

That takes care of the remaining problem (as far as I can tell).

I assume there is a good reason that Alias does not just delegate the inherited property, but the issues all do seem to have to do with the inherited property of aliases....

@pawamoy
Copy link
Member

pawamoy commented Aug 26, 2023

I assume there is a good reason that Alias does not just delegate the inherited property

There is not! Perfect catch! That's my fault, I didn't think of reapplying the property. Is this fix enough or is the hack in do_filter_objects still necessary?

@pawamoy
Copy link
Member

pawamoy commented Aug 26, 2023

It's more like this but you did find the right place:

@cached_property
def members(self) -> dict[str, Object | Alias]:  # noqa: D102
    final_target = self.final_target
    return {
        name: Alias(name, target=member, parent=self, inherited=False)
        for name, member in final_target.members.items()
    }


@cached_property
def inherited_members(self) -> dict[str, Alias]:  # noqa: D102
    final_target = self.final_target
    return {
        name: Alias(name, target=member, parent=self, inherited=True)
        for name, member in final_target.inherited_members.items()
    }

@pawamoy
Copy link
Member

pawamoy commented Aug 26, 2023

Fix released in v0.35.1.

@pawamoy pawamoy closed this as completed Aug 26, 2023
@analog-cbarber
Copy link
Author

This fix seems to do the trick.

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

No branches or pull requests

2 participants