From f1671b3375c08a55ae08ec49e7a209df36b18e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Dudfield?= Date: Sat, 20 May 2023 20:30:15 +0200 Subject: [PATCH 1/2] stubs: Fix RectValue so it can take floats too --- buildconfig/stubs/pygame/_common.pyi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/buildconfig/stubs/pygame/_common.pyi b/buildconfig/stubs/pygame/_common.pyi index f56d9b4036..bd139601f0 100644 --- a/buildconfig/stubs/pygame/_common.pyi +++ b/buildconfig/stubs/pygame/_common.pyi @@ -20,12 +20,15 @@ Coordinate = Union[Tuple[float, float], Sequence[float], Vector2] # This typehint is used when a function would return an RGBA tuble RGBAOutput = Tuple[int, int, int, int] ColorValue = Union[Color, int, str, Tuple[int, int, int], RGBAOutput, Sequence[int]] +from typing import Union +def my_function(my_var: Union[int, float, complex]) -> None: + print(my_var) _CanBeRect = Union[ Rect, - Tuple[int, int, int, int], + Tuple[Union[float, int], Union[float, int], Union[float, int], Union[float, int]], Tuple[Coordinate, Coordinate], - Sequence[int], + Sequence[Union[float, int]], Sequence[Coordinate], ] From 59b3e67c21162d0ba940839260eca24b93288113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Dudfield?= Date: Sat, 20 May 2023 20:33:21 +0200 Subject: [PATCH 2/2] examples textinput: Fix some type issues --- examples/textinput.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/examples/textinput.py b/examples/textinput.py index afab067ad9..8852a8fabf 100644 --- a/examples/textinput.py +++ b/examples/textinput.py @@ -7,6 +7,7 @@ """ import sys import os +from typing import List import pygame import pygame as pg @@ -24,16 +25,19 @@ class TextInput: # Add font name for each language, # otherwise some text can't be correctly displayed. - FONT_NAMES = [ - "notosanscjktcregular", - "notosansmonocjktcregular", - "notosansregular,", - "microsoftjhengheimicrosoftjhengheiuilight", - "microsoftyaheimicrosoftyaheiuilight", - "msgothicmsuigothicmspgothic", - "msmincho", - "Arial", - ] + FONT_NAMES = ",".join( + str(x) + for x in [ + "notosanscjktcregular", + "notosansmonocjktcregular", + "notosansregular,", + "microsoftjhengheimicrosoftjhengheiuilight", + "microsoftyaheimicrosoftyaheiuilight", + "msgothicmsuigothicmspgothic", + "msmincho", + "Arial", + ] + ) def __init__( self, prompt: str, pos, screen_dimensions, print_event: bool, text_color="white" @@ -50,12 +54,11 @@ def __init__( self._ime_text_pos = 0 self._ime_editing_text = "" self._ime_editing_pos = 0 - self.chat_list = [] + self.chat_list: List[str] = [] # Freetype # The font name can be a comma separated list # of font names to search for. - self.FONT_NAMES = ",".join(str(x) for x in self.FONT_NAMES) self.font = freetype.SysFont(self.FONT_NAMES, 24) self.font_small = freetype.SysFont(self.FONT_NAMES, 16) self.text_color = text_color