pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

Export types via something like `pygame.types` (3411)

Open GalacticEmperor1 opened this issue 2 years ago • 0 comments
trafficstars

Issue №3411 opened by illume at 2022-08-20 09:42:17

I want to accept a "# FFF" or a (255,255,255) or a Color('white') or a 'white'.

Can I do this somehow already?


Comments

# # ankith26 commented at 2022-08-20 09:53:14

I think at some point it would be wise to polish and expose the current internal _common.pyi typestub as pygame.types submodule (or any other sensible name, anything except pygame.common and the like).

Another alternative is to add these type definitions to their respective submodules directly, but this has the disadvantage of making things messy by having type stuff all over the place. For clarity and maintenance benefits IMHO it should be a centralised and dedicated submodule.


# # illume commented at 2022-08-20 11:44:50

I think I'd like to usecolor: pg.Color. Since it's easy to remember.

pg.ColorLike perhaps? Because maybe you want to always get a pg.Color, not a string or whatever.


# # ankith26 commented at 2022-08-20 11:56:43

I'm fine with ColorLike, and we can adopt the same convention for other things (RectLike, VectorLike, etc)

We can't have conflicting names with the actual concrete classes though, so we need some kind of prefix/suffix.

An alternative naming convention is SupportsColor, python typing seems to use it in some places... but it's a bit more verbose


# # blankRiot96 commented at 2022-09-25 07:57:14

A pygame._types submodule, or something akin to it would be convenient. I find myself needing to use the ColorValue defined in _common.pyi, and finding myself having to define Pos: TypeAlias = ... and RectLike: TypeAlias = ... often.

It would be really convenient if the versions of pygame going forward had inbuilt type aliases defined for imported usage, so one wouldn't have to dig into the source code to find the type alias they are looking for.

GalacticEmperor1 avatar Feb 12 '23 17:02 GalacticEmperor1