class MyClass:
x: int
y: str
- __match_args__ = ["x", "y"]
+ __match_args__ = ("x", "y")
@dataclasses.dataclass
def test_patma_200(self):
class Class:
- __match_args__ = ["a", "b"]
+ __match_args__ = ("a", "b")
c = Class()
c.a = 0
c.b = 1
class Parent:
__match_args__ = "a", "b"
class Child(Parent):
- __match_args__ = ["c", "d"]
+ __match_args__ = ("c", "d")
c = Child()
c.a = 0
c.b = 1
@no_perf
def test_patma_248(self):
class Class:
- __match_args__ = [None]
+ __match_args__ = (None,)
x = Class()
y = z = None
with self.assertRaises(TypeError):
@no_perf
def test_patma_249(self):
class Class:
- __match_args__ = []
+ __match_args__ = ()
x = Class()
y = z = None
with self.assertRaises(TypeError):
@no_perf
def test_patma_253(self):
class Class:
- __match_args__ = ["a", "a"]
+ __match_args__ = ("a", "a")
a = None
x = Class()
w = y = z = None
@no_perf
def test_patma_254(self):
class Class:
- __match_args__ = ["a"]
+ __match_args__ = ("a",)
a = None
x = Class()
w = y = z = None
self.assertEqual(x, range(10))
self.assertIs(y, None)
+ @no_perf
+ def test_patma_282(self):
+ class Class:
+ __match_args__ = ["spam", "eggs"]
+ spam = 0
+ eggs = 1
+ x = Class()
+ w = y = z = None
+ with self.assertRaises(TypeError):
+ match x:
+ case Class(y, z):
+ w = 0
+ self.assertIs(w, None)
+ self.assertIs(y, None)
+ self.assertIs(z, None)
+
class PerfPatma(TestPatma):
int match_self = 0;
match_args = PyObject_GetAttrString(type, "__match_args__");
if (match_args) {
- if (PyList_CheckExact(match_args)) {
- Py_SETREF(match_args, PyList_AsTuple(match_args));
- }
- if (match_args == NULL) {
- goto fail;
- }
if (!PyTuple_CheckExact(match_args)) {
- const char *e = "%s.__match_args__ must be a list or tuple "
- "(got %s)";
+ const char *e = "%s.__match_args__ must be a tuple (got %s)";
_PyErr_Format(tstate, PyExc_TypeError, e,
((PyTypeObject *)type)->tp_name,
Py_TYPE(match_args)->tp_name);