-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
not all members have is_package/is_module #226
Comments
Thanks for the report! The error in the traceback can be avoided with your commented line: However you're right that the module-kind properties are not exposed in the other kinds of objects (attribute, function, class), namely:
The I thought it made sense to have these properties on the import griffe
mamba = griffe.load("neo3")
for member in mamba.members.values():
if member.is_alias:
continue
if member.is_module and member.is_subpackage:
print(f"package: {member.name}")
elif member.is_module:
print(f"module: {member.name}") Well, if all objects have an |
It's all how you envisioned the API. I saw the I believe the problem might be with my mental model where I define a
So I believe the correct way would become import griffe
mamba = griffe.load("neo3")
for member in mamba.members.values():
if isinstance(member, griffe.Module):
if member.is_subpackage:
print(f"package: {member.name}")
else:
print(f"module: {member.name}") and the Feel free to close the issue if you plan to keep it as is or want to track it in another issue. |
The mental model to adopt when using Griffe is the one of a user of the Python code. I think I'll still copy the Module-specific properties to the generic Object class, where they'll always return False. And yeah I'll add everything to the API reference 🙂 |
Description of the bug
From the documentation I get that one way of navigating through a module is via its
members
property. As I'm playing around to see if it can replace my forked API generator (that has some issues) I tried to simply print the modules and subpackages in my package usingHowever it seems that not all member types have the
is_subpackage
oris_module
properties i.e.Alias
lacks at leastis_subpackage
andis_module
andAttribute
lacksis_subpackage
.I'm not sure if this is intentional or not.
To Reproduce
run example code from description
Full traceback
Full traceback
Expected behavior
I expected to easily test each member if it matches the type I want to filter on using
is_subpackage
and/oris_module
without errors.Environment information
griffe --debug-info # | xclip -selection clipboard
griffe
v0.38.0The text was updated successfully, but these errors were encountered: