2828)
2929
3030
31- class Company (StructuredNode ):
31+ class MypyCompany (StructuredNode ):
3232 """Test company node."""
3333
3434 name = StringProperty (required = True )
3535 founded_year = IntegerProperty ()
3636
3737
38- class Person (StructuredNode ):
38+ class MypyPerson (StructuredNode ):
3939 """Test person node with various property types."""
4040
4141 uid = UniqueIdProperty ()
@@ -51,20 +51,20 @@ class Person(StructuredNode):
5151
5252 # Relationships
5353 company : RelationshipTo = RelationshipTo (
54- "Company " , "WORKS_FOR" , cardinality = ZeroOrMore
54+ "MypyCompany " , "WORKS_FOR" , cardinality = ZeroOrMore
5555 )
5656 friends : RelationshipTo = RelationshipTo (
57- "Person " , "FRIEND_OF" , cardinality = ZeroOrMore
57+ "MypyPerson " , "FRIEND_OF" , cardinality = ZeroOrMore
5858 )
5959 managed_by : RelationshipFrom = RelationshipFrom (
60- "Person " , "MANAGES" , cardinality = ZeroOrMore
60+ "MypyPerson " , "MANAGES" , cardinality = ZeroOrMore
6161 )
6262
6363
6464# Test 1: Property type inference
6565def test_property_types () -> None :
6666 """Verify that property access returns correct types."""
67- person = Person ()
67+ person = MypyPerson ()
6868
6969 # These should all type-check correctly
7070 name_str : str = person .name
@@ -81,7 +81,7 @@ def test_property_types() -> None:
8181# Test 2: Property assignments
8282def test_property_assignments () -> None :
8383 """Verify that property assignments accept correct types."""
84- person = Person ()
84+ person = MypyPerson ()
8585
8686 # These should all type-check correctly
8787 person .name = "Alice"
@@ -98,16 +98,16 @@ def test_property_assignments() -> None:
9898def test_class_level_access () -> None :
9999 """Verify that class-level access returns the property descriptor."""
100100 # These should return the property classes themselves
101- name_prop : StringProperty = Person .name
102- age_prop : IntegerProperty = Person .age
103- height_prop : FloatProperty = Person .height
104- active_prop : BooleanProperty = Person .active
101+ name_prop : StringProperty = MypyPerson .name
102+ age_prop : IntegerProperty = MypyPerson .age
103+ height_prop : FloatProperty = MypyPerson .height
104+ active_prop : BooleanProperty = MypyPerson .active
105105
106106
107107# Test 4: Type errors should be caught
108108def test_type_errors () -> None :
109109 """These should produce type errors when checked with mypy."""
110- person = Person ()
110+ person = MypyPerson ()
111111
112112 # Type error: str incompatible with int
113113 wrong_type_1 : int = person .name # type: ignore[assignment]
@@ -125,7 +125,7 @@ def test_type_errors() -> None:
125125# Test 5: String operations on string properties
126126def test_string_operations () -> None :
127127 """Verify that string methods work on string properties."""
128- person = Person ()
128+ person = MypyPerson ()
129129 person .name = "alice"
130130
131131 # Should type-check: name is str, has .upper() method
@@ -141,7 +141,7 @@ def test_string_operations() -> None:
141141# Test 6: Numeric operations
142142def test_numeric_operations () -> None :
143143 """Verify that numeric operations work on numeric properties."""
144- person = Person ()
144+ person = MypyPerson ()
145145 person .age = 30
146146 person .height = 1.75
147147
@@ -156,20 +156,20 @@ def test_numeric_operations() -> None:
156156# Test 7: NodeSet operations
157157def test_nodeset_operations () -> None :
158158 """Verify NodeSet operations type-check correctly."""
159- # Should type-check: NodeSet[Person ] is correctly inferred
160- all_people : list [Person ] = Person .nodes .all ()
161- adults : "NodeSet[Person ]" = Person .nodes .filter (age__gte = 18 )
162- first_person : Person | None = Person .nodes .first ()
159+ # Should type-check: NodeSet[MypyPerson ] is correctly inferred
160+ all_people : list [MypyPerson ] = MypyPerson .nodes .all ()
161+ adults : "NodeSet[MypyPerson ]" = MypyPerson .nodes .filter (age__gte = 18 )
162+ first_person : MypyPerson | None = MypyPerson .nodes .first ()
163163
164164 # Chained operations maintain the generic type
165- filtered_people : "NodeSet[Person ]" = Person .nodes .filter ( age__gte = 18 ). exclude (
166- active = False
167- )
168- ordered_people : "NodeSet[Person ]" = Person .nodes .order_by ("name" )
165+ filtered_people : "NodeSet[MypyPerson ]" = MypyPerson .nodes .filter (
166+ age__gte = 18
167+ ). exclude ( active = False )
168+ ordered_people : "NodeSet[MypyPerson ]" = MypyPerson .nodes .order_by ("name" )
169169
170- # get() returns Person , not Any
171- specific_person : Person = Person .nodes .get (uid = "123" )
172- maybe_person : Person | None = Person .nodes .get_or_none (uid = "456" )
170+ # get() returns MypyPerson , not Any
171+ specific_person : MypyPerson = MypyPerson .nodes .get (uid = "123" )
172+ maybe_person : MypyPerson | None = MypyPerson .nodes .get_or_none (uid = "456" )
173173
174174 assert (
175175 all_people
@@ -185,28 +185,28 @@ def test_nodeset_operations() -> None:
185185# Test 8: Relationship operations
186186def test_relationship_operations () -> None :
187187 """Verify relationship operations type-check correctly."""
188- person = Person ()
189- company = Company ()
188+ person = MypyPerson ()
189+ company = MypyCompany ()
190190
191191 # Class-level access returns RelationshipDefinition
192- company_def = Person .company
193- friends_def = Person .friends
192+ company_def = MypyPerson .company
193+ friends_def = MypyPerson .friends
194194
195195 # Instance-level access returns RelationshipManager with correct generic type
196- # person.company is RelationshipManager[Company ]
197- # person.friends is RelationshipManager[Person ]
196+ # person.company is RelationshipManager[MypyCompany ]
197+ # person.friends is RelationshipManager[MypyPerson ]
198198
199199 # Connect should accept the correct node type
200200 person .company .connect (company )
201201 person .friends .connect (person )
202202
203203 # Type-safe relationship querying
204- all_companies : list [Company ] = person .company .all ()
205- single_company : Company | None = person .company .single ()
204+ all_companies : list [MypyCompany ] = person .company .all ()
205+ single_company : MypyCompany | None = person .company .single ()
206206 filtered_companies = person .company .filter (founded_year__gte = 2000 )
207207
208- all_friends : list [Person ] = person .friends .all ()
209- single_friend : Person | None = person .friends .single ()
208+ all_friends : list [MypyPerson ] = person .friends .all ()
209+ single_friend : MypyPerson | None = person .friends .single ()
210210
211211 # is_connected returns bool
212212 is_connected : bool = person .company .is_connected (company )
0 commit comments