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

Add some type hints to aid code completion in IDEs. #3103

Open
robfalck opened this issue Jan 22, 2024 · 0 comments
Open

Add some type hints to aid code completion in IDEs. #3103

robfalck opened this issue Jan 22, 2024 · 0 comments

Comments

@robfalck
Copy link
Contributor

Desired capability or behavior.

Type hints have been available in Python since 3.5. They have no impact on code execution, but can aid IDEs for autocompletion. OpenMDAO should add some hints for certain attributes and methods for which introspection is difficult.

For the first round of type hinting, OpenMDAO should provide hints for:

  • Problem.driver: typing.Type[Driver]
  • Problem.model: typing.Type[System]
  • Sytem.nonlinear_solver: typing.Type[NonlinearSolver]
  • System.linear_solver: typing.Type[LinearSolver]
  • NonlinearSolver.linesearch: typing.Type[LinesearchSolver]

And Group.add_subsystem, which returns the same type input

T = TypeVar("T", bound="System")

def self.add_subsystem(self, subsys=typing.Type[T], ...) -> T:

Note that the build-in function type replaces typing.Type as of 3.8, but we still support older versions.

Testing

Various linters are available to detect that these types are being applied correctly. mypy is common for static analysis, but others are available and may work better in our CI system.

Associated POEM

N/A

@robfalck robfalck assigned robfalck and unassigned robfalck Jan 22, 2024
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

No branches or pull requests

1 participant