You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the cls.members is coming from a griffe.Class object I'm not sure if this is a bug there rather than in this extension, but I suspect that it's much more likely to crop up here as typically you would avoid using id as an object attribute.
UPDATE: I loaded in my package using griffe in my interpreter and I found the real cause of the bug. It seems that the field doesn't exist on the Class object because I guess griffe does not include the inherited attributes from the base class (where id is defined)?
I would guess a fix might be to use cls.all_members?
Yep, seems like the solution!
However! During dynamic analysis, common.process_function will run while the package is not entirely loaded. Using all_members would be bad: it computes inherited members, and if Griffe didn't yet see the base classes, some inherited members will be missing, and we'll likely get a key error again. If we want to use all_members safely, then we have to refactor the extension to use on_package_loaded for dynamic analysis as well. Which means the current hooks (on_class_instance, on_attribute_instance, on_function_instance, on_class_members) should only record the objects somewhere (in a dict, self._objects[obj.path] = obj). Then we would iterate on those in on_package_loaded. Something like that 😅
mkdocstrings/griffe#347 could alleviate the need to wait for the whole package to be loaded, but this is a consequent effort.
Description of the bug
I believe if you create a validator method on a field calledid
that it will cause an error:Docs were building fine until I added the following validator to my model:
Since thecls.members
is coming from agriffe.Class
object I'm not sure if this is a bug there rather than in this extension, but I suspect that it's much more likely to crop up here as typically you would avoid usingid
as an object attribute.UPDATE: I loaded in my package using
griffe
in my interpreter and I found the real cause of the bug. It seems that the field doesn't exist on theClass
object because I guessgriffe
does not include the inherited attributes from the base class (whereid
is defined)?So I think MRE:
I would guess a fix might be to use
cls.all_members
?The text was updated successfully, but these errors were encountered: