mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
Issue #18531: Single var-keyword argument of dict subtype was passed
unscathed to the C-defined function. Now it is converted to exact dict.
This commit is contained in:
parent
a26e4b97d8
commit
ce41287e99
4 changed files with 82 additions and 1 deletions
|
|
@ -70,6 +70,12 @@ class BadInt3(int):
|
|||
def __int__(self):
|
||||
return True
|
||||
|
||||
class TupleSubclass(tuple):
|
||||
pass
|
||||
|
||||
class DictSubclass(dict):
|
||||
pass
|
||||
|
||||
|
||||
class Unsigned_TestCase(unittest.TestCase):
|
||||
def test_b(self):
|
||||
|
|
@ -321,6 +327,33 @@ class Boolean_TestCase(unittest.TestCase):
|
|||
|
||||
|
||||
class Tuple_TestCase(unittest.TestCase):
|
||||
def test_args(self):
|
||||
from _testcapi import get_args
|
||||
|
||||
ret = get_args(1, 2)
|
||||
self.assertEqual(ret, (1, 2))
|
||||
self.assertIs(type(ret), tuple)
|
||||
|
||||
ret = get_args(1, *(2, 3))
|
||||
self.assertEqual(ret, (1, 2, 3))
|
||||
self.assertIs(type(ret), tuple)
|
||||
|
||||
ret = get_args(*[1, 2])
|
||||
self.assertEqual(ret, (1, 2))
|
||||
self.assertIs(type(ret), tuple)
|
||||
|
||||
ret = get_args(*TupleSubclass([1, 2]))
|
||||
self.assertEqual(ret, (1, 2))
|
||||
self.assertIs(type(ret), tuple)
|
||||
|
||||
ret = get_args()
|
||||
self.assertIn(ret, ((), None))
|
||||
self.assertIn(type(ret), (tuple, type(None)))
|
||||
|
||||
ret = get_args(*())
|
||||
self.assertIn(ret, ((), None))
|
||||
self.assertIn(type(ret), (tuple, type(None)))
|
||||
|
||||
def test_tuple(self):
|
||||
from _testcapi import getargs_tuple
|
||||
|
||||
|
|
@ -336,6 +369,29 @@ class Tuple_TestCase(unittest.TestCase):
|
|||
self.assertRaises(TypeError, getargs_tuple, 1, seq())
|
||||
|
||||
class Keywords_TestCase(unittest.TestCase):
|
||||
def test_kwargs(self):
|
||||
from _testcapi import get_kwargs
|
||||
|
||||
ret = get_kwargs(a=1, b=2)
|
||||
self.assertEqual(ret, {'a': 1, 'b': 2})
|
||||
self.assertIs(type(ret), dict)
|
||||
|
||||
ret = get_kwargs(a=1, **{'b': 2, 'c': 3})
|
||||
self.assertEqual(ret, {'a': 1, 'b': 2, 'c': 3})
|
||||
self.assertIs(type(ret), dict)
|
||||
|
||||
ret = get_kwargs(**DictSubclass({'a': 1, 'b': 2}))
|
||||
self.assertEqual(ret, {'a': 1, 'b': 2})
|
||||
self.assertIs(type(ret), dict)
|
||||
|
||||
ret = get_kwargs()
|
||||
self.assertIn(ret, ({}, None))
|
||||
self.assertIn(type(ret), (dict, type(None)))
|
||||
|
||||
ret = get_kwargs(**{})
|
||||
self.assertIn(ret, ({}, None))
|
||||
self.assertIn(type(ret), (dict, type(None)))
|
||||
|
||||
def test_positional_args(self):
|
||||
# using all positional args
|
||||
self.assertEqual(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue