Skip to content

Commit c9af31f

Browse files
authored
Throw attribute error NIRNode constructor (#122)
Fix for #120 Throws `AttributeError` on call `NIRNode.__init__`.
1 parent 9ce2a26 commit c9af31f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

nir/ir/node.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
from abc import ABC
12
from dataclasses import asdict, dataclass
23
from typing import Any, Dict
34

45

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

20+
def __init__(self) -> None:
21+
raise AttributeError("NIRNode does not have a default constructor.")
22+
1923
def __eq__(self, other):
2024
return self is other
2125

tests/test_ir.py

+10
Original file line numberDiff line numberDiff line change
@@ -582,3 +582,13 @@ def test_conv_type_inference():
582582
raise AssertionError(f"type check failed for: {name}")
583583
graph.infer_types()
584584
assert graph._check_types(), f"type inference failed for: {name}"
585+
586+
587+
def test_node():
588+
try:
589+
node = nir.ir.NIRNode()
590+
assert (
591+
node is None
592+
), f"test failed, we should not be able to construct an NIRNode: {node}"
593+
except AttributeError:
594+
pass

0 commit comments

Comments
 (0)