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

PEP572 Use Python's assignment expression #2782

Merged
merged 2 commits into from
Apr 9, 2024
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
3 changes: 1 addition & 2 deletions buildconfig/msysio.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ def print_(*args, **kwds):

stream = kwds.get('file', sys.stdout)
sep = kwds.get('sep', ' ')
end = kwds.get('end', '\n')

if args:
stream.write(sep.join([str(arg) for arg in args]))
if end:
if end := kwds.get('end', '\n'):
stream.write(end)
try:
stream.flush()
Expand Down
3 changes: 1 addition & 2 deletions src_py/sprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,7 @@ def remove_internal(self, sprite):

:param sprite: The sprite we are removing.
"""
lost_rect = self.spritedict[sprite]
if lost_rect:
if lost_rect := self.spritedict[sprite]:
self.lostsprites.append(lost_rect)
del self.spritedict[sprite]

Expand Down
3 changes: 1 addition & 2 deletions src_py/sysfont.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ def _font_finder_darwin():
"/System/Library/Fonts/Supplemental",
]

username = os.getenv("USER")
if username:
if username := os.getenv("USER"):
locations.append(f"/Users/{username}/Library/Fonts")

strange_root = "/System/Library/Assets/com_apple_MobileAsset_Font3"
Expand Down
18 changes: 6 additions & 12 deletions test/controller_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,19 @@ def _get_first_controller(self):
return controller.Controller(i)

def test_construction(self):
c = self._get_first_controller()
if c:
if c := self._get_first_controller():
self.assertIsInstance(c, controller.Controller)
else:
self.skipTest("No controller connected")

def test__auto_init(self):
c = self._get_first_controller()
if c:
if c := self._get_first_controller():
self.assertTrue(c.get_init())
else:
self.skipTest("No controller connected")

def test_get_init(self):
c = self._get_first_controller()
if c:
if c := self._get_first_controller():
self.assertTrue(c.get_init())
c.quit()
self.assertFalse(c.get_init())
Expand All @@ -111,25 +108,22 @@ def test_from_joystick(self):
self.assertIsInstance(c, controller.Controller)

def test_as_joystick(self):
c = self._get_first_controller()
if c:
if c := self._get_first_controller():
joy = c.as_joystick()
self.assertIsInstance(joy, type(pygame.joystick.Joystick(0)))
else:
self.skipTest("No controller connected")

def test_get_mapping(self):
c = self._get_first_controller()
if c:
if c := self._get_first_controller():
mapping = c.get_mapping()
self.assertIsInstance(mapping, dict)
self.assertIsNotNone(mapping["a"])
else:
self.skipTest("No controller connected")

def test_set_mapping(self):
c = self._get_first_controller()
if c:
if c := self._get_first_controller():
mapping = c.get_mapping()
mapping["a"] = "b3"
mapping["y"] = "b0"
Expand Down
3 changes: 1 addition & 2 deletions test/mask_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def random_mask(size=(100, 100)):

def maskFromSurface(surface, threshold=127):
mask = pygame.Mask(surface.get_size())
key = surface.get_colorkey()
if key:
if key := surface.get_colorkey():
for y in range(surface.get_height()):
for x in range(surface.get_width()):
if surface.get_at((x + 0.1, y + 0.1)) != key:
Expand Down
7 changes: 2 additions & 5 deletions test/mixer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ def test_set_soundfont(self):
mixer.init()

# test that initially, get_soundfont returns only real files
initial_sf = mixer.get_soundfont()
if initial_sf is not None:
if (initial_sf := mixer.get_soundfont()) is not None:
for i in initial_sf.split(";"):
os.path.exists(i)

Expand Down Expand Up @@ -552,9 +551,7 @@ def test_find_channel(self):
filename = example_path(os.path.join("data", "house_lo.wav"))
sound = mixer.Sound(file=filename)

num_channels = mixer.get_num_channels()

if num_channels > 0:
if (num_channels := mixer.get_num_channels()) > 0:
found_channel = mixer.find_channel()
self.assertIsNotNone(found_channel)

Expand Down
3 changes: 1 addition & 2 deletions test/test_utils/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ def combine_results(all_results, t):


def get_test_results(raw_return):
test_results = TEST_RESULTS_RE.search(raw_return)
if test_results:
if test_results := TEST_RESULTS_RE.search(raw_return):
try:
return eval(test_results.group(1))
except:
Expand Down
Loading