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

Provide support for dynamically generated classes and __init__ options for IDE autocompletion, etc #1548

Open
lbianchi-lbl opened this issue Dec 12, 2024 · 1 comment
Assignees
Labels
Priority:Normal Normal Priority Issue or PR

Comments

@lbianchi-lbl
Copy link
Contributor

  • The way ProcessBlock subclasses are dynamically created through the @declare_process_block_class decorator is not compatible with tools that rely on static analysis of the code
  • This includes pylint, which prompted my initial analysis of the problem (see FIXME for details), and ultimately required the creation of a (fairly complex) pylint plugin
  • This also includes code IDEs, which severely limits the hints that can be provided to the user, in turn limiting the usability of IDAES as a platform
  • Changing the current API to one that's more friendly to static analysis is not a viable option because of backward compatibility concerns and the amount of effort it would require
  • To address this, I'm currently investigating a solutions based on type stub files (.pyi), which are companion files distributed alongside the code that allow providing type annotation information without modifying the actual code
@lbianchi-lbl lbianchi-lbl self-assigned this Dec 12, 2024
@ksbeattie ksbeattie added the Priority:Normal Normal Priority Issue or PR label Dec 12, 2024
@aspitarl
Copy link

There is a similar issue with pandas/xarray accessor methods and IDE autocomplete. Finding out about stubs led me to this recent package which solves that issue for xarray: https://pypi.org/project/accessor-stubs/. The project description gives a good overview of the problem. It fixed my autocomplete issue by overwriting the .pyi files in a package xarray-stubs in my virtual environment (thanks for the tip!)

Perhaps a similar solution could autogenerate the ProcessBlock stubs. I think it is a similar problem, as xarray accessors are defined using decorators. Though it looks as if there is a more generalized stub generation tool built into mypy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:Normal Normal Priority Issue or PR
Projects
None yet
Development

No branches or pull requests

3 participants