Skip to content

Return NotImplemented from unsupported rich comparisons in SFML bindings#182

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-sfml-vector2-comparison
Draft

Return NotImplemented from unsupported rich comparisons in SFML bindings#182
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-sfml-vector2-comparison

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 24, 2026

Unsupported rich comparisons in the bindings were surfacing the wrong Python error path. In particular, ordering comparisons could end up raising from raise NotImplemented instead of following Python’s comparison protocol and producing the standard “operator not supported” TypeError.

  • Binding fix

    • Change sfml.graphics.Rect.__richcmp__ to return NotImplemented for unsupported comparison operators.
    • This aligns the binding with Python’s rich comparison contract: only ==/!= are implemented, while ordering falls back to the interpreter.
  • Regression coverage

    • Tighten the Vector2 comparison test to assert the expected Python behavior rather than accepting any TypeError.
    • Add equivalent coverage for Rect so unsupported ordering comparisons cannot regress back to the incorrect BaseException error path.
  • Behavioral impact

    • Equality and inequality remain supported.
    • Ordering comparisons now fail the Python-native way.
import sfml.system as system
import sfml.graphics as graphics

system.Vector2(10, 10) == system.Vector2(10, 10)   # True
graphics.Rect((0, 0), (1, 1)) != graphics.Rect((1, 1), (1, 1))  # True

system.Vector2(10, 10) > system.Vector2(10, 10)
# TypeError: '>' not supported between instances of 'sfml.system.Vector2' and 'sfml.system.Vector2'

graphics.Rect((0, 0), (1, 1)) > graphics.Rect((0, 0), (1, 1))
# TypeError: '>' not supported between instances of 'sfml.graphics.Rect' and 'sfml.graphics.Rect'
Original prompt

This section details on the original issue you should resolve

<issue_title>sfml.system.Vector2 comparison raises wrong type</issue_title>
<issue_description>The rich compare for sfml Vector2 is broken.

import sfml
a = sfml.system.Vector2(10, 10)
b = sfml.system.Vector2(10, 10)
a == b
a > b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "src/sfml/system/system.pyx", line 124, in sfml.system.Vector2.__richcmp__
TypeError: raise: exception class must be a subclass of BaseException

I traced the problem to 'src/sfml/system/system.pyx' line 124:
raise NotImplemented

NotImplemented is not supposed to be raised. I propose to either do:
return NotImplemented

or maybe raise an error like this one:

abs(sfml.system.Vector2(1, 2))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: bad operand type for abs(): 'sfml.system.Vector2'

I can implement the solution if needed.
</issue_description>

<agent_instructions>Implement a solution for this issue, if it's still relevant.
Also make sure that it's how a proper Python binding should behave.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI changed the title [WIP] Fix sfml.system.Vector2 comparison raising wrong type Return NotImplemented from unsupported rich comparisons in SFML bindings Mar 24, 2026
Copilot AI requested a review from intjelic March 24, 2026 17:31
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.

sfml.system.Vector2 comparison raises wrong type

2 participants