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

Explicitly prevent the instantiation of abstract classes #202

Merged
merged 1 commit into from
Mar 15, 2024

Conversation

alihamdan
Copy link
Member

@alihamdan alihamdan commented Mar 15, 2024

Closes #188

Inheriting from ABC (or using ABCMeta as a metaclass) prevents the instantiation of classes that have abstract methods but not classes without abstract methods. This PR improves the error in case someone tries to instantiate Element, AbstractLoad, or AbstractBranch. I used the same error type and message used by ABC. An example before and after:

Before
could raise any error; currently raises:

>>> lf.AbstractLoad("load", bus=lf.Bus("bus", phases="abcn"), powers=[-1e3, -1e3, -1e3])
AttributeError: 'AbstractLoad' object has no attribute 'type'

After
always raises

>>> lf.AbstractLoad("load", bus=lf.Bus("bus", phases="abcn"), powers=[-1e3, -1e3, -1e3])
TypeError: Can't instantiate abstract class AbstractLoad

@alihamdan alihamdan added the enhancement New feature or request label Mar 15, 2024
@alihamdan alihamdan requested a review from benoit9126 March 15, 2024 14:57
@alihamdan alihamdan self-assigned this Mar 15, 2024
@alihamdan alihamdan merged commit a2fd4e5 into develop Mar 15, 2024
4 checks passed
@alihamdan alihamdan deleted the abstract branch March 15, 2024 16:53
@benoit9126 benoit9126 mentioned this pull request Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Explicitly prevent the instantiation of abstract classes
2 participants