Skip to content

Implementing warnings system and pygame.debug #2944

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
16 changes: 14 additions & 2 deletions buildconfig/stubs/gen_stubs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
buildconfig/stubs/gen_stubs.py
A script to auto-generate locals.pyi, constants.pyi and __init__.pyi typestubs
A script to auto-generate locals.pyi, constants.pyi, debug.pyi and __init__.pyi typestubs
"""

import pathlib
Expand Down Expand Up @@ -104,8 +104,15 @@ def get_all(mod: Any):
except KeyError:
pygame_all_imports[f".{k}"] = val

# this is overriden by __init__.py
if ".base" in pygame_all_imports and "warn" in pygame_all_imports[".base"]:
pygame_all_imports[".base"].remove("warn")

# misc stubs that must be added to __init__.pyi
misc_stubs = """"""
misc_stubs = """from typing import Type

def warn(message: str, urgency: int, level: int = 2, category: Type[Warning] = RuntimeWarning): ...
"""

# write constants.pyi file
constants_file = pathlib.Path(__file__).parent / "pygame" / "constants.pyi"
Expand Down Expand Up @@ -142,6 +149,11 @@ def get_all(mod: Any):
f.write(f" {item} as {item},\n")
f.write(")\n")

# write debug.pyi file
debug_file = pathlib.Path(__file__).parent / "pygame" / "debug.pyi"
with open(init_file, "r") as i, open(debug_file, "w") as f:
f.write(i.read())

# write locals.pyi file
locals_file = pathlib.Path(__file__).parent / "pygame" / "locals.pyi"
with open(locals_file, "w") as f:
Expand Down
7 changes: 6 additions & 1 deletion buildconfig/stubs/pygame/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# buildconfig/stubs/gen_stubs.py
# A script to auto-generate locals.pyi, constants.pyi and __init__.pyi typestubs
# A script to auto-generate locals.pyi, constants.pyi, debug.pyi and __init__.pyi typestubs
# IMPORTANT NOTE: Do not edit this file by hand!
from typing import Type

def warn(message: str, urgency: int, level: int = 2, category: Type[Warning] = RuntimeWarning): ...

from pygame import (
display as display,
Expand Down Expand Up @@ -65,10 +68,12 @@ from .base import (
get_init as get_init,
get_sdl_byteorder as get_sdl_byteorder,
get_sdl_version as get_sdl_version,
get_warnings_filter as get_warnings_filter,
init as init,
quit as quit,
register_quit as register_quit,
set_error as set_error,
set_warnings_filter as set_warnings_filter,
)

from .rwobject import (
Expand Down
5 changes: 4 additions & 1 deletion buildconfig/stubs/pygame/base.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Tuple, Callable
from typing import Any, Tuple, Callable, Type

__version__: str

Expand All @@ -19,3 +19,6 @@ def register_quit(callable: Callable[[], Any], /) -> None: ...

# undocumented part of pygame API, kept here to make stubtest happy
def get_array_interface(arg: Any, /) -> dict: ...
def warn(message: str, category: Type[Warning], level: int, urgency: int, /): ...
def get_warnings_filter() -> int: ...
def set_warnings_filter(val: int, /): ...
2 changes: 1 addition & 1 deletion buildconfig/stubs/pygame/constants.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# buildconfig/stubs/gen_stubs.py
# A script to auto-generate locals.pyi, constants.pyi and __init__.pyi typestubs
# A script to auto-generate locals.pyi, constants.pyi, debug.pyi and __init__.pyi typestubs
# IMPORTANT NOTE: Do not edit this file by hand!

ACTIVEEVENT: int
Expand Down
Loading
Loading