Skip to content

Griffe backend #444

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

Open
AWhetter opened this issue May 8, 2024 · 3 comments
Open

Griffe backend #444

AWhetter opened this issue May 8, 2024 · 3 comments
Assignees
Labels
Other Improvement Improvements that aren't targeted at users

Comments

@AWhetter
Copy link
Collaborator

AWhetter commented May 8, 2024

We currently implement a custom parser using astroid. While this allows us to fix issues as needed, we may be able to get faster and more frequent fixes by utilising a parser that already exists.
Try griffe. See if it can handle all of the situations that we currently support, and more!

@AWhetter AWhetter added the Other Improvement Improvements that aren't targeted at users label May 8, 2024
@pawamoy
Copy link

pawamoy commented May 10, 2024

Hey, Griffe maintainer here 👋 (can't help but stalk GitHub issues 😅)

I think Astroid has some inference capabilities that help resolving indirections during static analysis. If sphinx-autoapi is using this feature, you could find limitations in Griffe's ability to do the same.

Obviously we can't infer everything statically so Griffe tries to stay very humble about it and doesn't do too clever things. The other reason is it also supports dynamic analysis (either selectively/per-object, or globally soon), so for complex cases it can always fallback to dynamic analysis.

In any case, happy to help here if needed!

@AWhetter
Copy link
Collaborator Author

@pawamoy I've started using Griffe and I'm loving it so far!

I have a question. How can I figure out the metaclass of a class? Is it only stored in Class.bases as an Expr?

The bigger goal here is to establish if the class is abstract or not. When using astroid I check the metaclass, base classes, and method decorators (

def is_abstract_class(node: astroid.nodes.ClassDef) -> bool:
metaclass = node.metaclass()
if metaclass and metaclass.name == "ABCMeta":
return True
if "abc.ABC" in node.basenames:
return True
if any(method.is_abstract(pass_is_abstract=False) for method in node.methods()):
return True
return False
). It would be amazing if Griffe could figure out if a class is abstract on its own, but what I'm trying to do is quite high level so maybe out of scope for Griffe.

@pawamoy
Copy link

pawamoy commented Mar 25, 2025

Awesome ❤

Yep, currently the only way to find the metaclass is through the expressions representing class bases. We already have API to check if an expression is an enum, enum value, etc., so I'm totally open to add more API to check if an expression is a metaclass, and to add relevant methods/properties to the models (my_class.metaclass, my_class["method"].is_abstract, etc.) 🙂

Don't hesitate to open feature requests on Griffe's tracker 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Other Improvement Improvements that aren't targeted at users
Projects
None yet
Development

No branches or pull requests

2 participants