0

This is really weird, but I'm making a custom vector using pygame's Vector2 as a parent, and any attempt to define an attribute that starts with the letters x or y results in an error upon initialization. If the x is anywhere else in the attribute name, it works fine.

For example, this works fine:

class CustomVector(pygame.Vector2):
    def __init__(self,vector,attribute):
        super().__init__(vector)
        self.attribute = attribute

CustomVector((0,0),True)

This also works fine:

class CustomVector(pygame.Vector2):
    def __init__(self,vector,attribute):
        super().__init__(vector)
        self.attributex = attribute

CustomVector((0,0),True)

But this raises an error:

class CustomVector(pygame.Vector2):
    def __init__(self,vector,attribute):
        super().__init__(vector)
        self.xattribute = attribute

CustomVector((0,0),True)

The error raised is generally TypeError: a sequence is expected, but I've gotten others

Per John Gordon, here is the whole error message. There is another error, but it is clearly stated that it is the direct result of the TypeError:

TypeError: a sequence is expected

The above exception was the direct cause of the following exception:


Traceback (most recent call last):


File "c:\Users\ajhom\Documents\Monster\code\test.py", line 14, in <module>
CustomVector((0,0),True)
~~~~~~~~~~~~^^^^^^^^^^^^
SystemError: <function CustomVector.__init__ at 0x000002B7C347EDE0> returned a result with an exception set
4
  • Are you subclassing pygame.Vector2 or pygame.math.Vector2? pygame.org/docs/ref/math.html#pygame.math.Vector2 Commented Feb 10 at 0:01
  • 1
    Don't make us guess where the error happens. Please edit the question and add the full error traceback message. Commented Feb 10 at 0:08
  • 1
    pygame's Vector classes do have special handling for attributes with names consisting of x, y, z, and w only: for example, you can assign a 2-element tuple to the attribute yx if the coordinates are in the opposite order from what you want to put in the Vector. There is a fallthrough to handle attribute names like yours - but it only gets checked after values have been retrieved for the xyzw characters in the name, so the assignment fails if the value wasn't a tuple or other sequence of sufficient length. Commented Feb 10 at 0:44
  • 1
    @jasonharper I think you should upgrade this comment to an answer. Commented Feb 10 at 2:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.