From 75f738316ac8d593076ec84e75b6ab636c617f2a Mon Sep 17 00:00:00 2001 From: DigiDuncan Date: Mon, 8 Jul 2024 05:21:14 -0400 Subject: [PATCH 1/2] int typing to float because pyglet is lying --- arcade/text.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/arcade/text.py b/arcade/text.py index edda469c07..d69be3a55b 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -61,16 +61,13 @@ def _attempt_font_name_resolution(font_name: FontNameOrNames) -> FontNameOrNames :return: Either a resolved path or the original tuple """ if font_name: - # ensure if isinstance(font_name, str): font_list: tuple[str, ...] = (font_name,) elif isinstance(font_name, tuple): font_list = font_name else: - raise TypeError( - "font_name parameter must be a string, or a tuple of strings that specify a font name." - ) + raise TypeError("font_name parameter must be a string, or a tuple of strings that specify a font name.") for font in font_list: try: @@ -174,8 +171,8 @@ class Text: def __init__( self, text: str, - x: int, - y: int, + x: float, + y: float, color: RGBOrA255 = arcade.color.WHITE, font_size: float = 12, width: Optional[int] = 0, @@ -189,7 +186,7 @@ def __init__( rotation: float = 0, batch: Optional[pyglet.graphics.Batch] = None, group: Optional[pyglet.graphics.Group] = None, - z: int = 0, + z: float = 0, ): # Raises a RuntimeError if no window for better user feedback arcade.get_window() @@ -203,9 +200,10 @@ def __init__( adjusted_font = _attempt_font_name_resolution(font_name) self._label = pyglet.text.Label( text=text, - x=x, - y=y, - z=z, + # pyglet is lying about what it takes here and float is entirely valid + x=x, # type: ignore + y=y, # type: ignore + z=z, # type: ignore font_name=adjusted_font, font_size=font_size, # use type: ignore since cast is slow & pyglet used Literal From 34e3e61e0015e286c7176fcaf2b8dd2373f3e667 Mon Sep 17 00:00:00 2001 From: DigiDuncan Date: Mon, 8 Jul 2024 05:30:27 -0400 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8black=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arcade/text.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arcade/text.py b/arcade/text.py index d69be3a55b..a59d082c7e 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -67,7 +67,9 @@ def _attempt_font_name_resolution(font_name: FontNameOrNames) -> FontNameOrNames elif isinstance(font_name, tuple): font_list = font_name else: - raise TypeError("font_name parameter must be a string, or a tuple of strings that specify a font name.") + raise TypeError( + "font_name parameter must be a string, or a tuple of strings that specify a font name." + ) for font in font_list: try: