From a0712ed0308f94de669a554c643eec1beaa709ea Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Mon, 27 Nov 2023 21:55:18 +0100 Subject: [PATCH 1/2] fix types --- arcade/gl/context.py | 5 ++++- arcade/gui/widgets/__init__.py | 11 ++++++++--- pyproject.toml | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/arcade/gl/context.py b/arcade/gl/context.py index a20979007..dee569352 100644 --- a/arcade/gl/context.py +++ b/arcade/gl/context.py @@ -296,7 +296,10 @@ def window(self) -> Window: :type: ``pyglet.Window`` """ - return self._window_ref() + window_ref = self._window_ref() + if window_ref is None: + raise Exception("Window not available, lost referenz.") + return window_ref @property def screen(self) -> Framebuffer: diff --git a/arcade/gui/widgets/__init__.py b/arcade/gui/widgets/__init__.py index d40fcc9eb..0cea1a297 100644 --- a/arcade/gui/widgets/__init__.py +++ b/arcade/gui/widgets/__init__.py @@ -1,5 +1,6 @@ from __future__ import annotations +import builtins from abc import ABC from random import randint from typing import ( @@ -13,9 +14,9 @@ List, Dict, ) -from typing_extensions import Self from pyglet.event import EventDispatcher, EVENT_HANDLED, EVENT_UNHANDLED +from typing_extensions import Self import arcade from arcade import Sprite, get_window, Texture @@ -38,7 +39,6 @@ __all__ = ["Surface", "UIDummy"] - class Rect(NamedTuple): """ Representing a rectangle for GUI module. @@ -546,7 +546,12 @@ def with_border(self, width=2, color=(0, 0, 0)) -> Self: return self def with_padding( - self, top=..., right=..., bottom=..., left=..., all=... + self, + top: Union["builtins.ellipsis", int] = ..., + right: Union["builtins.ellipsis", int] = ..., + bottom: Union["builtins.ellipsis", int] = ..., + left: Union["builtins.ellipsis", int] = ..., + all: Union["builtins.ellipsis", int] = ... ) -> "UIWidget": """ Changes the padding to the given values if set. Returns itself diff --git a/pyproject.toml b/pyproject.toml index d2ee0a475..b72c7e91a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ dev = [ "pygments==2.16.1", "docutils==0.20.1", "furo", - "pyright==1.1.322", + "pyright==1.1.337", "pyyaml==6.0.1", "sphinx==7.2.2", "sphinx-autobuild==2021.3.14", From 0b22eef8ec799671ee12048f81dc1baa6de188a2 Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Mon, 27 Nov 2023 22:13:38 +0100 Subject: [PATCH 2/2] fix types --- arcade/gl/context.py | 10 ++++++++-- arcade/gui/style.py | 8 +++++++- arcade/gui/widgets/__init__.py | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/arcade/gl/context.py b/arcade/gl/context.py index dee569352..5aa6d3c84 100644 --- a/arcade/gl/context.py +++ b/arcade/gl/context.py @@ -6,7 +6,7 @@ from contextlib import contextmanager from ctypes import c_char_p, c_float, c_int, cast from typing import (Any, Deque, Dict, Iterable, List, Optional, Sequence, Set, Tuple, - Union) + Union, overload, Literal) import pyglet import pyglet.gl.lib @@ -1301,7 +1301,7 @@ def __init__(self, ctx): self.MAX_TEXTURE_MAX_ANISOTROPY = self.get_float(gl.GL_MAX_TEXTURE_MAX_ANISOTROPY, 1.0) #: The maximum support window or framebuffer viewport. #: This is usually the same as the maximum texture size - self.MAX_VIEWPORT_DIMS = self.get_int_tuple(gl.GL_MAX_VIEWPORT_DIMS, 2) + self.MAX_VIEWPORT_DIMS: Tuple[int, int] = self.get_int_tuple(gl.GL_MAX_VIEWPORT_DIMS, 2) #: How many buffers we can have as output when doing a transform(feedback). #: This is usually 4 self.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = self.get(gl.GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS) @@ -1314,6 +1314,12 @@ def __init__(self, ctx): warn("Error happened while querying of limits. Moving on ..") + @overload + def get_int_tuple(self, enum: GLenumLike, length: Literal[2]) -> Tuple[int, int]:... + + @overload + def get_int_tuple(self, enum: GLenumLike, length: int) -> Tuple[int, ...]:... + def get_int_tuple(self, enum: GLenumLike, length: int): """Get an enum as an int tuple""" try: diff --git a/arcade/gui/style.py b/arcade/gui/style.py index 67238103c..af52424ca 100644 --- a/arcade/gui/style.py +++ b/arcade/gui/style.py @@ -2,7 +2,7 @@ from abc import abstractmethod from dataclasses import dataclass -from typing import Mapping, TypeVar, Generic +from typing import Mapping, TypeVar, Generic, overload, Any from arcade.gui.property import DictProperty from arcade.gui.widgets import UIWidget @@ -18,6 +18,12 @@ class UIStyleBase: A styled widget should own a dataclass, which subclasses this class """ + @overload + def get(self, key, default: str) -> str: ... + + @overload + def get(self, key, default: Any) -> Any: ... + def get(self, key, default=None): return self[key] if key in self else default diff --git a/arcade/gui/widgets/__init__.py b/arcade/gui/widgets/__init__.py index 0cea1a297..281870cc8 100644 --- a/arcade/gui/widgets/__init__.py +++ b/arcade/gui/widgets/__init__.py @@ -572,7 +572,7 @@ def with_padding( def with_background( self, *, - color=..., + color: Union["builtins.ellipsis", Color]=..., texture: Union[None, Texture, NinePatchTexture] = ..., # type: ignore ) -> "UIWidget":