While writing my game in pygame I was trying to use the XOR (^) binary operator to 'toggle' flags any flag I passed to a function. However I kept running into Overflow errors (and Warning: re-creating window in toggle_fullscreen action() errors).
To debug this I tried to use the & operator to check if the flags were being properly detected and compare it to the constant value provided by pygame.
print(pygame.display.get_surface().get_flags() & exampleflag, exampleflag)
While this worked when checking for pygame.NOFRAME (the result was 0 32 when not in borderless mode and 32 32 when in borderless.
But when trying to check for pygame.SCALED which is always enabled in my game it would always output 0 512 even though pygame.SCALED was present and I was expecting 512 512.
Also when checking for pygame.FULLSCREEN (I was toggling it using pygame.display.toggle_fullscreen() if this helps in any way) the result was 0 -2147483648 (was expecting 0 0 since the window was not fullscreen) which is obviously not correct and probably why I was getting Overflow errors.
I don't really understand how pygame flags work beyond what the basic binary operators are meant to do to them since it is not documented very well (the fact that you can check for flags using & itself was discovered by me on another question on stack overflow). Can someone explain why this is happening?
pygame.Surface.get_flags.&. Boolean AND operator in Python isand. Both of them are binary operators (as are**and%, for example), as opposed to e.g. unarynot.