From ec57db17a37c31ac022e7fd47e909f9efd0da18d Mon Sep 17 00:00:00 2001 From: Nick Papior Date: Fri, 11 Oct 2024 13:32:06 +0200 Subject: [PATCH] safety net in doc creation when adding more dispatchers This should warn when adding new dispatchers, and also indicate exactly which one is missing. Also made nice use of the whalrus op. Signed-off-by: Nick Papior --- docs/conf.py | 14 ++++++++++++++ src/sisl/_dispatcher.py | 1 + 2 files changed, 15 insertions(+) diff --git a/docs/conf.py b/docs/conf.py index 31aa67f30f..ae83d3f86e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -743,11 +743,15 @@ def yield_types(obj: object, classes): pass +_found_dispatch_attributes = set() for obj in yield_objects(sisl): for name, attr in yield_types(obj, sisl._dispatcher.AbstractDispatcher): # Fix the class dispatchers methods assign_class_dispatcher_methods(obj, name, as_attributes=True) + # Collect all the different names where a dispatcher is associated. + # In this way we die if we add a new one, without documenting it! + _found_dispatch_attributes.add(name) for name, attr in yield_types( obj, (sisl.io._multiple.SileBound, sisl.io._multiple.SileBinder) @@ -756,6 +760,16 @@ def yield_types(obj: object, classes): assign_nested_attribute(obj, name, attr.__wrapped__) +if ( + len( + diff := _found_dispatch_attributes + - set(autosummary_context["sisl_dispatch_attributes"]) + ) + > 0 +): + raise ValueError(f"Found more sets than defined: {diff}") + + def sisl_skip(app, what, name, obj, skip, options): global autodoc_default_options, autosummary_context # When adding routines here, please also add them diff --git a/src/sisl/_dispatcher.py b/src/sisl/_dispatcher.py index bd2f5e2b5a..1fc181a47d 100644 --- a/src/sisl/_dispatcher.py +++ b/src/sisl/_dispatcher.py @@ -110,6 +110,7 @@ def dispatch(self, method): A basic interception would be .. code:: python + @wraps(method) def func(*args, **kwargs): return method(*args, **kwargs)