@@ -128,6 +128,86 @@ def test_mismatched_string_literals_no_match(self):
128128 assert result is None
129129
130130
131+ class TestCrossTypeLiteralMatching :
132+ """Tests that literals of different Python types never match each other."""
133+
134+ def setup_method (self ):
135+ TemplateEngine .clear_cache ()
136+
137+ def teardown_method (self ):
138+ TemplateEngine .clear_cache ()
139+
140+ def test_none_does_not_match_bytes_literal (self ):
141+ """None should not match b''."""
142+ pattern_tree = TemplateEngine .get_template_tree ("None" , {})
143+ target_tree = TemplateEngine .get_template_tree ('b""' , {})
144+ cursor = _make_cursor (target_tree )
145+
146+ comparator = PatternMatchingComparator ({})
147+ result = comparator .match (pattern_tree , target_tree , cursor )
148+ assert result is None
149+
150+ def test_none_does_not_match_nonempty_bytes (self ):
151+ """None should not match b'hello'."""
152+ pattern_tree = TemplateEngine .get_template_tree ("None" , {})
153+ target_tree = TemplateEngine .get_template_tree ('b"hello"' , {})
154+ cursor = _make_cursor (target_tree )
155+
156+ comparator = PatternMatchingComparator ({})
157+ result = comparator .match (pattern_tree , target_tree , cursor )
158+ assert result is None
159+
160+ def test_none_does_not_match_empty_string (self ):
161+ """None should not match ''."""
162+ pattern_tree = TemplateEngine .get_template_tree ("None" , {})
163+ target_tree = TemplateEngine .get_template_tree ('""' , {})
164+ cursor = _make_cursor (target_tree )
165+
166+ comparator = PatternMatchingComparator ({})
167+ result = comparator .match (pattern_tree , target_tree , cursor )
168+ assert result is None
169+
170+ def test_none_does_not_match_zero (self ):
171+ """None should not match 0."""
172+ pattern_tree = TemplateEngine .get_template_tree ("None" , {})
173+ target_tree = TemplateEngine .get_template_tree ("0" , {})
174+ cursor = _make_cursor (target_tree )
175+
176+ comparator = PatternMatchingComparator ({})
177+ result = comparator .match (pattern_tree , target_tree , cursor )
178+ assert result is None
179+
180+ def test_none_matches_none (self ):
181+ """None should match None."""
182+ pattern_tree = TemplateEngine .get_template_tree ("None" , {})
183+ target_tree = TemplateEngine .get_template_tree ("None" , {})
184+ cursor = _make_cursor (target_tree )
185+
186+ comparator = PatternMatchingComparator ({})
187+ result = comparator .match (pattern_tree , target_tree , cursor )
188+ assert result is not None
189+
190+ def test_none_does_not_match_ellipsis (self ):
191+ """None should not match ... (Ellipsis) — both have value=None internally."""
192+ pattern_tree = TemplateEngine .get_template_tree ("None" , {})
193+ target_tree = TemplateEngine .get_template_tree ("..." , {})
194+ cursor = _make_cursor (target_tree )
195+
196+ comparator = PatternMatchingComparator ({})
197+ result = comparator .match (pattern_tree , target_tree , cursor )
198+ assert result is None
199+
200+ def test_bytes_does_not_match_string (self ):
201+ """b'hello' should not match 'hello'."""
202+ pattern_tree = TemplateEngine .get_template_tree ('b"hello"' , {})
203+ target_tree = TemplateEngine .get_template_tree ('"hello"' , {})
204+ cursor = _make_cursor (target_tree )
205+
206+ comparator = PatternMatchingComparator ({})
207+ result = comparator .match (pattern_tree , target_tree , cursor )
208+ assert result is None
209+
210+
131211class TestMethodInvocationMatching :
132212 """Tests for method invocation comparison."""
133213
0 commit comments