Skip to content

Commit 9111d6c

Browse files
authored
Merge pull request #2743 from oddbookworm/undeprecate-draw-aaline-blend
Undeprecate draw aaline blend
2 parents 5a4acb6 + 0e75467 commit 9111d6c

File tree

3 files changed

+70
-11
lines changed

3 files changed

+70
-11
lines changed

docs/reST/ref/draw.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
6262
| if ``width > 0``, used for line thickness
6363
| if ``width < 0``, nothing will be drawn
6464
|
65-
65+
6666
.. versionchangedold:: 2.1.1
67-
Drawing rects with width now draws the width correctly inside the
68-
rect's area, rather than using an internal call to draw.lines(),
67+
Drawing rects with width now draws the width correctly inside the
68+
rect's area, rather than using an internal call to draw.lines(),
6969
which had half the width spill outside the rect area.
7070

7171
:param int border_radius: (optional) used for drawing rectangle with rounded corners.
@@ -498,6 +498,7 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
498498

499499
.. versionchangedold:: 2.0.0 Added support for keyword arguments.
500500
.. versionchanged:: 2.4.0 Removed deprecated 'blend' argument
501+
.. versionchanged:: 2.5.0 ``blend`` argument readded for backcompat, but will always raise a deprecation exception when used
501502

502503
.. ## pygame.draw.aaline ##
503504
@@ -536,7 +537,8 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
536537
contain number pairs
537538

538539
.. versionchangedold:: 2.0.0 Added support for keyword arguments.
539-
.. versionchanged:: 2.4.0 Removed deprecated 'blend' argument
540+
.. versionchanged:: 2.4.0 Removed deprecated ``blend`` argument
541+
.. versionchanged:: 2.5.0 ``blend`` argument readded for backcompat, but will always raise a deprecation exception when used
540542

541543
.. ## pygame.draw.aalines ##
542544

src_c/draw.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,29 @@ aaline(PyObject *self, PyObject *arg, PyObject *kwargs)
105105
PyObject *colorobj, *start, *end;
106106
SDL_Surface *surf = NULL;
107107
float startx, starty, endx, endy;
108+
PyObject *blend = NULL;
108109
int drawn_area[4] = {INT_MAX, INT_MAX, INT_MIN,
109110
INT_MIN}; /* Used to store bounding box values */
110111
Uint32 color;
111-
static char *keywords[] = {"surface", "color", "start_pos", "end_pos",
112-
NULL};
112+
static char *keywords[] = {"surface", "color", "start_pos",
113+
"end_pos", "blend", NULL};
113114

114-
if (!PyArg_ParseTupleAndKeywords(arg, kwargs, "O!OOO|i", keywords,
115+
if (!PyArg_ParseTupleAndKeywords(arg, kwargs, "O!OOO|O", keywords,
115116
&pgSurface_Type, &surfobj, &colorobj,
116-
&start, &end)) {
117+
&start, &end, &blend)) {
117118
return NULL; /* Exception already set. */
118119
}
119120

121+
if (blend != NULL) {
122+
if (PyErr_WarnEx(
123+
PyExc_DeprecationWarning,
124+
"blend argument is deprecated and has no functionality and "
125+
"will be completely removed in a future version of pygame-ce",
126+
1) == -1) {
127+
return NULL;
128+
}
129+
}
130+
120131
surf = pgSurface_AsSurface(surfobj);
121132
SURF_INIT_CHECK(surf)
122133

@@ -239,18 +250,30 @@ aalines(PyObject *self, PyObject *arg, PyObject *kwargs)
239250
float *xlist, *ylist;
240251
float x, y;
241252
int l, t;
253+
PyObject *blend = NULL;
242254
int drawn_area[4] = {INT_MAX, INT_MAX, INT_MIN,
243255
INT_MIN}; /* Used to store bounding box values */
244256
int result, closed;
245257
Py_ssize_t loop, length;
246-
static char *keywords[] = {"surface", "color", "closed", "points", NULL};
258+
static char *keywords[] = {"surface", "color", "closed",
259+
"points", "blend", NULL};
247260

248-
if (!PyArg_ParseTupleAndKeywords(arg, kwargs, "O!OpO|i", keywords,
261+
if (!PyArg_ParseTupleAndKeywords(arg, kwargs, "O!OpO|O", keywords,
249262
&pgSurface_Type, &surfobj, &colorobj,
250-
&closed, &points)) {
263+
&closed, &points, &blend)) {
251264
return NULL; /* Exception already set. */
252265
}
253266

267+
if (blend != NULL) {
268+
if (PyErr_WarnEx(
269+
PyExc_DeprecationWarning,
270+
"blend argument is deprecated and has no functionality and "
271+
"will be completely removed in a future version of pygame-ce",
272+
1) == -1) {
273+
return NULL;
274+
}
275+
}
276+
254277
surf = pgSurface_AsSurface(surfobj);
255278
SURF_INIT_CHECK(surf)
256279

test/draw_test.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,6 +2445,21 @@ def test_aaline__args(self):
24452445

24462446
self.assertIsInstance(bounds_rect, pygame.Rect)
24472447

2448+
def test_aaline__blend_warning(self):
2449+
"""Using the blend argument should raise a DeprecationWarning"""
2450+
faulty_blend_values = [0, 1, True, False, None, "", [], type]
2451+
with warnings.catch_warnings(record=True) as w:
2452+
for count, blend in enumerate(faulty_blend_values):
2453+
# Cause all warnings to always be triggered.
2454+
warnings.simplefilter("always")
2455+
# Trigger DeprecationWarning.
2456+
self.draw_aaline(
2457+
pygame.Surface((2, 2)), (0, 0, 0, 50), (0, 0), (2, 2), blend
2458+
)
2459+
# Check if there is only one warning and is a DeprecationWarning.
2460+
self.assertEqual(len(w), count + 1)
2461+
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
2462+
24482463
def test_aaline__kwargs(self):
24492464
"""Ensures draw aaline accepts the correct kwargs"""
24502465
surface = pygame.Surface((4, 4))
@@ -3169,6 +3184,25 @@ def test_aalines__args(self):
31693184

31703185
self.assertIsInstance(bounds_rect, pygame.Rect)
31713186

3187+
def test_aalines__blend_warning(self):
3188+
"""Using the blend argument should raise a DeprecationWarning"""
3189+
faulty_blend_values = [0, 1, True, False, None, "", [], type]
3190+
with warnings.catch_warnings(record=True) as w:
3191+
for count, blend in enumerate(faulty_blend_values):
3192+
# Cause all warnings to always be triggered.
3193+
warnings.simplefilter("always")
3194+
# Trigger DeprecationWarning.
3195+
self.draw_aalines(
3196+
pygame.Surface((2, 2)),
3197+
(0, 0, 0, 50),
3198+
False,
3199+
((0, 0), (1, 1)),
3200+
blend,
3201+
)
3202+
# Check if there is only one warning and is a DeprecationWarning.
3203+
self.assertEqual(len(w), count + 1)
3204+
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
3205+
31723206
def test_aalines__kwargs(self):
31733207
"""Ensures draw aalines accepts the correct kwargs."""
31743208
surface = pygame.Surface((4, 4))

0 commit comments

Comments
 (0)