Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
PEP 646: Use stdbool.h; separate test cases
  • Loading branch information
mrahtz committed Jan 25, 2022
commit 456156a3106fa2d05c0ce155313697af9668bd66
7 changes: 4 additions & 3 deletions Lib/test/test_genericalias.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from queue import Queue, SimpleQueue
from weakref import WeakSet, ReferenceType, ref
import typing
from typing import Callable, Dict, List

from typing import TypeVar, TypeVarTuple
T = TypeVar('T')
Expand Down Expand Up @@ -178,9 +179,7 @@ def test_exposed_type(self):
self.assertEqual(a.__args__, (int,))
self.assertEqual(a.__parameters__, ())

def test_parameters(self):
from typing import List, Dict, Callable

def test_dict_parameters(self):
D0 = dict[str, int]
self.assertEqual(D0.__args__, (str, int))
self.assertEqual(D0.__parameters__, ())
Expand All @@ -197,6 +196,7 @@ def test_parameters(self):
self.assertEqual(D2b.__args__, (T, T))
self.assertEqual(D2b.__parameters__, (T,))

Comment thread
mrahtz marked this conversation as resolved.
def test_list_parameters(self):
L0 = list[str]
self.assertEqual(L0.__args__, (str,))
self.assertEqual(L0.__parameters__, ())
Expand All @@ -219,6 +219,7 @@ def test_parameters(self):
self.assertEqual(L5.__args__, (Callable[[K, V], K],))
self.assertEqual(L5.__parameters__, (K, V))

def test_tuple_parameters(self):
with self.assertRaises(TypeError):
tuple[*list[int]]

Expand Down
6 changes: 4 additions & 2 deletions Objects/genericaliasobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "pycore_unionobject.h" // _Py_union_type_or, _PyGenericAlias_Check
#include "structmember.h" // PyMemberDef

#include <stdbool.h>

typedef struct {
PyObject_HEAD
PyObject *origin;
Expand All @@ -13,7 +15,7 @@ typedef struct {
PyObject* weakreflist;
// Whether we're a starred type, e.g. *tuple[int].
// Only supported for `tuple`.
int starred;
bool starred;
} gaobject;

typedef struct {
Expand Down Expand Up @@ -646,7 +648,7 @@ ga_iternext(gaiterobject *gi) {
}
gaobject *alias = (gaobject *) gi->obj;
PyObject *starred_tuple = Py_GenericAlias(alias->origin, alias->args);
((gaobject * ) starred_tuple)->starred = 1;
((gaobject * ) starred_tuple)->starred = true;
Py_SETREF(gi->obj, NULL);
return starred_tuple;
}
Expand Down