Skip to content
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

autompc.control.nmpc: fix broken and unused include #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mikebentley15
Copy link
Contributor

Description

The Sphinx documentation generation issues many warnings. One of them appears to be missing optional dependencies even though I installed all dependencies and optional dependencies into a Conda environment:

Missing optional dependency for NMPC
[...]
WARNING: autodoc: failed to import class 'DirectTranscriptionControllerFactory' from module 'autompc.control'; the following exception was raised:
Traceback (most recent call last):
  File "/home/bentley/miniconda3/envs/autompc/lib/python3.10/site-packages/sphinx/util/inspect.py", line 440, in safe_getattr
    return getattr(obj, name, *defargs)
AttributeError: module 'autompc.control' has no attribute 'DirectTranscriptionControllerFactory'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/bentley/miniconda3/envs/autompc/lib/python3.10/site-packages/sphinx/ext/autodoc/importer.py", line 102, in import_object
    obj = attrgetter(obj, mangled_name)
  File "/home/bentley/miniconda3/envs/autompc/lib/python3.10/site-packages/sphinx/ext/autodoc/__init__.py", line 327, in get_attr
    return autodoc_attrgetter(self.env.app, obj, name, *defargs)
  File "/home/bentley/miniconda3/envs/autompc/lib/python3.10/site-packages/sphinx/ext/autodoc/__init__.py", line 2827, in autodoc_attrgetter
    return safe_getattr(obj, name, *defargs)
  File "/home/bentley/miniconda3/envs/autompc/lib/python3.10/site-packages/sphinx/util/inspect.py", line 456, in safe_getattr
    raise AttributeError(name) from exc
AttributeError: DirectTranscriptionControllerFactory

Investigating further, the DirectTranscriptionControllerFactory class is included from autompc/control/__init__.py like so

try:
    from .nmpc import DirectTranscriptionController, DirectTranscriptionControllerFactory
except ImportError:
    print("Missing optional dependency for NMPC")

It turns out this try..except block was hiding a bug because the include that failed to import was

from collections import Iterable

The Iterable class is in collections.abc, not collections. Further, this Iterable class is not used in the file at all.

Proposed solution

Remove the inclusion of Iterable in autompc/control/nmpc.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant