Skip to content

Vector{2,3}.__delattr__ messaging fixed when deleting x, y, {z} and removed Vector4 zombies - #3069

Merged
MyreMylar merged 2 commits into
pygame-community:mainfrom
oddbookworm:vector-fixes
Aug 30, 2024
Merged

MyreMylar merged 2 commits into
pygame-community:mainfrom
oddbookworm:vector-fixes

Conversation

@oddbookworm

Copy link
Copy Markdown
Member

Fixes #3066 and removes the remnants of whatever Vector4 used to be there

@oddbookworm oddbookworm added the math pygame.math label Aug 20, 2024
@oddbookworm
oddbookworm requested a review from a team as a code owner August 20, 2024 03:20
Comment thread src_c/math.c Outdated
break;
}
case 2: {
if (self->dim >= 3) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this check needed? I think in this path an error should be raised either way regardless of dim value

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Differentiate between vector2 and vector3. This also guarantees the old behavior of going to badinternalcall if somehow someone manages to get a vec2 with a z property

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code checked for

if (component >= self->dim) {
    PyErr_BadInternalCall();
}

Irrespective of the status of value but the changes do not preserve this behaviour.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the check

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your latest commit didn't address what I was trying to say.

Consider a call where value != NULL && component >= self->dim. In this case the old code correctly raises an error but the new code doesn't. The PyErr_BadInternalCall check should happen independently of the NULL check outside the block and above it.

@ankith26 ankith26 added this to the 2.5.2 milestone Aug 20, 2024

@Starbuck5 Starbuck5 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

@MyreMylar MyreMylar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, LGTM. The code makes sense and I can verify that the new tests fail before this PR is compiled and pass afterwards (tested locally).

@MyreMylar
MyreMylar merged commit 431e35c into pygame-community:main Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

math pygame.math

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect error message for vectors

4 participants