Can this be used to just check for compatibility breaks with the __init__.py's __all__ exports? #230
-
I may misunderstand the goals of this project, but it looks like it would be useful for checking for breaks in public interface, even thought python doesn't really have anything private except for maybe nested functions. There is the convention that the But griffe seems to assume the radical opposite, that everything that is reachable is part of the public interface, so almost any additional coding would be a semver major change. So is there a way to, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
In Python, the convention is that any object that does not start with an underscore Griffe also actually supports If you don't want to prefix most objects with
...and then expose just what you want to make public in from package._mod_a import A
from package._mod_b import B
__all__ = ["A", "B"] If you don't want to make modules private, you can even prefix the package itself:
# src/package/__init__.py
from _package.mod_a import A
from _package.mod_b import B
__all__ = ["A", "B"] (...and include both With that in mind, I believe Griffe's assumptions are correct and expected. Happy to hear your thoughts 🙂 |
Beta Was this translation helpful? Give feedback.
In Python, the convention is that any object that does not start with an underscore
_
is considered public. That comprises modules, functions, classes, methods and any attributes. If you want to mark an object as "private" (or "protected", I never remember which one uses name mangling with two leading underscores__
), you must prefix it with_
.Griffe also actually supports
__all__
attributes. If you define one in a module (any module, not just__init__.py
), then Griffe knows that only the names within__all__
are to be considered public, even if other objects not in__all__
do not start with_
. If you don't define__all__
, then Griffe falls back on whether objects in the module start with_