-
-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Pyright throws an expected 0 positional arguments
or Cannot assign to attribute "x" for class "SDL_FRect" Attribute "x" is unknown
for classes like SDL_FRect
, as it will not see the parameters for them.
I am not sure if the blame is on Pyright's or the project's side here.
# __init__.py
class SDL_POINTER:
@classmethod
def __class_getitem__(cls, key: type) -> type:
"""Create a ctypes pointer type from a ctypes type."""
if not (__frozen__ or __release__):
assert not isinstance(key, tuple), "Expected a single argument, got a tuple."
assert isinstance(key, type), "Expected a type as the first argument."
return ctypes.POINTER(key)
# SDL_rect.py
from .__init__ import ctypes, typing, abc, \
SDL_POINTER, SDL_FUNC, SDL_DEREFERENCE, SDL_BINARY
class SDL_FRect(ctypes.Structure):
_fields_ = [
("x", ctypes.c_float),
("y", ctypes.c_float),
("w", ctypes.c_float),
("h", ctypes.c_float)
]
LP_SDL_FRect: typing.TypeAlias = SDL_POINTER[SDL_FRect]
# project using the library
self.rect = sdl3.SDL_FRect(0, 0, p_w.contents.value, p_h.contents.value)
# Pyright
Expected 0 positional arguments
Pyright seems to see it as "SDL_POINTER" which takes no arguments
Looks like this is very likely directly caused by this library relying on star imports.
from sdl3.SDL import * # type: ignore
EDIT: Or not, but that's not helping for sure.
The class annotation is redundant too:
https://docs.python.org/3/reference/datamodel.html#object.__class_getitem__
When defined on a class, __class_getitem__() is automatically a class method.
As such, there is no need for it to be decorated with @classmethod when it is defined.
Metadata
Metadata
Assignees
Labels
No labels