Skip to content

Commit

Permalink
Throw attribute error NIRNode constructor
Browse files Browse the repository at this point in the history
Fix for #120

Throws `AttributeError` on call `NIRNode.__init__`.
  • Loading branch information
hanleyc01 committed Jan 20, 2025
1 parent 9ce2a26 commit 6774e19
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nir/ir/node.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from abc import ABC
from dataclasses import asdict, dataclass
from typing import Any, Dict


@dataclass(eq=False)
class NIRNode:
class NIRNode(ABC):
"""Base superclass of Neural Intermediate Representation Unit (NIR).
All NIR primitives inherit from this class, but NIRNodes should never be
Expand All @@ -16,6 +17,9 @@ class NIRNode:
# output_type: Dict[str, np.ndarray] = field(init=False, kw_only=True)
# metadata: Dict[str, Any] = field(init=True, default_factory=dict)

def __init__(self) -> None:
raise AttributeError("NIRNode does not have a default constructor.")

def __eq__(self, other):
return self is other

Expand Down
10 changes: 10 additions & 0 deletions tests/test_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,13 @@ def test_conv_type_inference():
raise AssertionError(f"type check failed for: {name}")
graph.infer_types()
assert graph._check_types(), f"type inference failed for: {name}"


def test_node():
try:
node = nir.ir.NIRNode()
assert (
node is None
), f"test failed, we should not be able to construct an NIRNode: {node}"
except AttributeError:
pass

0 comments on commit 6774e19

Please sign in to comment.