Skip to content
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

A simple start towards an implementation of import pygame.debug #3148

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions buildconfig/stubs/mypy_allow_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ pygame\.pypm
pygame\._sdl2\.mixer
pygame\.sysfont.*
pygame\.docs.*
pygame\.debug
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess that this change is here is that there's no debug.pyi stub, correct?

11 changes: 3 additions & 8 deletions src_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import os
import sys
import platform
import warnings

# Choose Windows display driver
if os.name == "nt":
Expand Down Expand Up @@ -93,8 +94,6 @@ def warn(self):
msg_type = "import" if self.urgent else "use"
message = f"{msg_type} {self.name}: {self.info}\n({self.reason})"
try:
import warnings

level = 4 if self.urgent else 3
warnings.warn(message, RuntimeWarning, level)
except ImportError:
Expand Down Expand Up @@ -395,11 +394,7 @@ def __color_reduce(c):

copyreg.pickle(Color, __color_reduce, __color_constructor)

if "PYGAME_HIDE_SUPPORT_PROMPT" not in os.environ:
print(
f"pygame-ce {ver} (SDL {'.'.join(map(str, get_sdl_version()))}, "
f"Python {platform.python_version()})"
)
warnings.filterwarnings("ignore")
MyreMylar marked this conversation as resolved.
Show resolved Hide resolved

# cleanup namespace
del pygame, os, sys, platform, MissingModule, copyreg, packager_imports
del pygame, os, sys, platform, warnings, MissingModule, copyreg, packager_imports
16 changes: 16 additions & 0 deletions src_py/debug.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of currently, using:

import pygame.debug
pygame.do_stuff()

Works, as also:

import pygame.debug
import pygame as pg
from pygame import do_stuff

pg.do_stuff()
do_stuff()

But not:

import pygame.debug as pg
from pygame.debug import do_stuff

pg.do_stuff()
do_stuff()

What's your stance on this? If the last behavio(u)r is desired, adding

from pygame import *

Or

def __getattr__(name):
    return getattr(pygame, name)

def __dir__():
    return dir(pygame)

Should suffice, but if doing so, the debug.pyi stub should be created (edit buildconfig/stubs/gen_stubs.py to copy __init__.pyi stub).

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
import platform
import warnings
import pygame

if "PYGAME_HIDE_SUPPORT_PROMPT" not in os.environ:
print(
f"pygame-ce {pygame.version.ver} (SDL {'.'.join(map(str, pygame.base.get_sdl_version()))}, "
f"Python {platform.python_version()})"
)

pygame.print_debug_info()

warnings.filterwarnings("default")

del os, platform, warnings
1 change: 1 addition & 0 deletions src_py/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ python_sources = files(
'camera.py',
'colordict.py',
'cursors.py',
'debug.py',
'freetype.py',
'ftfont.py',
'locals.py',
Expand Down
Loading