Skip to content

Conversation

@hanleyc01
Copy link
Contributor

Fix for #120

  • Added inheritance to NIRNode from abc. This might be too much, but given that the stated documentation for NIRNode is that it is a "base superclass" and that "NIRNodes should never be instantiated", indicating this property through inheritance in a Pythonic way.
  • Throws AttributeError on call NIRNode.__init__ as a proposed fix for Issue 120.
  • Added a simple test test_node which checks if a NIRNode class can be constructed. All tests pass, it seems.

Potential Downsides

  • Inheriting from abc.ABC might have some unintended consequences in behavior that I am not familiar with, this change I think can be discarded if there are any unintended problems that arise.
  • This solution might be a little clumsy and lead to unclear API usage. For example, if a user introspects at runtime on the methods of NIRNode, they will find that __init__ is in fact defined. However, the exception raised here is one used to indicate that there is in fact no __init__ method. One potential alternative is to raise TypeError, which "may be raised by user code to indicate that an attempted operation on an object is not supported, and is not meant to be".

P.S. This is my first attempted contribution to an open-source library ❤️

Fix for neuromorphs#120

Throws `AttributeError` on call `NIRNode.__init__`.
@Jegp
Copy link
Collaborator

Jegp commented Feb 9, 2025

Hi @hanleyc01! Thank you for your pull request (and your patience in our reply :-) )!

This looks great, really. You're correct that this should throw if initialized, because it's not a valid computational primitive in NIR. All tests passed so I'll just go ahead and merge. Congratulations on your first contribution! Don't hesitate to join the discussion on Discord and come back with more changes ;-)

@Jegp Jegp merged commit c9af31f into neuromorphs:main Feb 9, 2025
4 checks passed
@hanleyc01
Copy link
Contributor Author

Hi @hanleyc01! Thank you for your pull request (and your patience in our reply :-) )!

This looks great, really. You're correct that this should throw if initialized, because it's not a valid computational primitive in NIR. All tests passed so I'll just go ahead and merge. Congratulations on your first contribution! Don't hesitate to join the discussion on Discord and come back with more changes ;-)

Thanks so much! I'm glad to have helped, and I'm currently in the discord. I'm preparing for conference submissions with my lab until around the end of this month, but once I get more free time I'll try and get more active in the participation.

Jegp pushed a commit that referenced this pull request Feb 13, 2025
Fix for #120

Throws `AttributeError` on call `NIRNode.__init__`.
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.

2 participants