Skip to content

fix pyright errors #1933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions arcade/gl/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1298,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)
Expand All @@ -1311,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:
Expand Down
8 changes: 7 additions & 1 deletion arcade/gui/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
13 changes: 9 additions & 4 deletions arcade/gui/widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import builtins
from abc import ABC
from random import randint
from typing import (
Expand All @@ -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
Expand All @@ -38,7 +39,6 @@

__all__ = ["Surface", "UIDummy"]


class Rect(NamedTuple):
"""
Representing a rectangle for GUI module.
Expand Down Expand Up @@ -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
Expand All @@ -567,7 +572,7 @@ def with_padding(
def with_background(
self,
*,
color=...,
color: Union["builtins.ellipsis", Color]=...,
texture: Union[None, Texture, NinePatchTexture] = ..., # type: ignore
) -> "UIWidget":

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down