-
Notifications
You must be signed in to change notification settings - Fork 0
Hua work miscs #15
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
Hua work miscs #15
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| include src/rda_python_miscs/*.usg | ||
| include src/rda_python_miscs/rst_templates/*.temp |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1119,9 +1119,10 @@ def load_opts_alias(self, docname): | |||||||||||||||||
|
|
||||||||||||||||||
| Resolution order for OPTS / ALIAS: | ||||||||||||||||||
|
|
||||||||||||||||||
| 1. Module-level ``OPTS`` / ``ALIAS`` attributes. | ||||||||||||||||||
| 2. The first class *defined in that module* that carries both ``OPTS`` | ||||||||||||||||||
| and ``ALIAS`` as class-level attributes. | ||||||||||||||||||
| 1. The first class *defined in that module* that carries ``OPTS`` | ||||||||||||||||||
| as a class-level attribute. | ||||||||||||||||||
| 2. Module-level ``OPTS`` / ``ALIAS`` attributes (fallback when no | ||||||||||||||||||
| qualifying class is found). | ||||||||||||||||||
|
|
||||||||||||||||||
| ``ALIAS`` is optional; an empty dict is returned when not found. | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -1155,25 +1156,26 @@ def load_opts_alias(self, docname): | |||||||||||||||||
| # Derive ORIGIN from the module's own file path. | ||||||||||||||||||
| origin = op.dirname(op.abspath(mod.__file__)) | ||||||||||||||||||
|
|
||||||||||||||||||
| # 1. Try module-level attributes first. | ||||||||||||||||||
| opts = getattr(mod, 'OPTS', None) | ||||||||||||||||||
| alias = getattr(mod, 'ALIAS', None) | ||||||||||||||||||
|
|
||||||||||||||||||
| # 2. Fall back to the first class in the module that owns both. | ||||||||||||||||||
| if opts is None or alias is None: | ||||||||||||||||||
| for _, obj in inspect.getmembers(mod, inspect.isclass): | ||||||||||||||||||
| if obj.__module__ == modname: | ||||||||||||||||||
| cls_opts = getattr(obj, 'OPTS', None) | ||||||||||||||||||
| cls_alias = getattr(obj, 'ALIAS', None) | ||||||||||||||||||
| if cls_opts is not None: | ||||||||||||||||||
| if opts is None: opts = cls_opts | ||||||||||||||||||
| if alias is None: alias = cls_alias | ||||||||||||||||||
| break | ||||||||||||||||||
| # 1. Find the first class defined in this module and read OPTS / ALIAS from it. | ||||||||||||||||||
| cls = next( | ||||||||||||||||||
| (obj for _, obj in inspect.getmembers(mod, inspect.isclass) | ||||||||||||||||||
| if obj.__module__ == modname), | ||||||||||||||||||
| None, | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| if cls is not None: | ||||||||||||||||||
| obj = cls() | ||||||||||||||||||
| opts = getattr(obj, 'OPTS', None) | ||||||||||||||||||
| alias = getattr(obj, 'ALIAS', None) | ||||||||||||||||||
|
Comment on lines
+1167
to
+1169
|
||||||||||||||||||
| obj = cls() | |
| opts = getattr(obj, 'OPTS', None) | |
| alias = getattr(obj, 'ALIAS', None) | |
| # Read class-level attributes directly from the class to avoid | |
| # instantiating it (which may require constructor arguments or | |
| # trigger side effects in __init__). | |
| opts = getattr(cls, 'OPTS', None) | |
| alias = getattr(cls, 'ALIAS', None) |
Copilot
AI
Mar 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a module defines at least one class but that first class doesn't have OPTS, this code will not fall back to module-level OPTS even though the docstring describes module-level as a fallback when no qualifying class is found. Consider continuing to search for a class that defines OPTS, or falling back to module-level when opts is still None after checking the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inspect.getmembers(mod, inspect.isclass)returns members sorted by name, not in source-definition order, so this doesn't actually select the “first class defined in that module” as the docstring states. If definition order matters, iterate overmod.__dict__(insertion-ordered) and filter classes from there, or adjust the wording to match the actual behavior.