Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(82073)

Delta Between Two Patch Sets: Lib/test/test_inspect.py

Issue 19611: inspect.getcallargs doesn't properly interpret set comprehension code objects.
Left Patch Set: Created 3 years, 2 months ago
Right Patch Set: Created 3 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/inspect.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 import builtins 1 import builtins
2 import collections 2 import collections
3 import datetime 3 import datetime
4 import functools 4 import functools
5 import importlib 5 import importlib
6 import inspect 6 import inspect
7 import io 7 import io
8 import linecache 8 import linecache
9 import os 9 import os
10 from os.path import normcase 10 from os.path import normcase
(...skipping 2972 matching lines...) Expand 10 before | Expand all | Expand 10 after
2983 with self.assertRaisesRegex(ValueError, 'invalid value for'): 2983 with self.assertRaisesRegex(ValueError, 'invalid value for'):
2984 p2 = p2.replace(kind=p2.empty) 2984 p2 = p2.replace(kind=p2.empty)
2985 2985
2986 p2 = p2.replace(kind=p2.KEYWORD_ONLY) 2986 p2 = p2.replace(kind=p2.KEYWORD_ONLY)
2987 self.assertEqual(p2, p) 2987 self.assertEqual(p2, p)
2988 2988
2989 def test_signature_parameter_positional_only(self): 2989 def test_signature_parameter_positional_only(self):
2990 with self.assertRaisesRegex(TypeError, 'name must be a str'): 2990 with self.assertRaisesRegex(TypeError, 'name must be a str'):
2991 inspect.Parameter(None, kind=inspect.Parameter.POSITIONAL_ONLY) 2991 inspect.Parameter(None, kind=inspect.Parameter.POSITIONAL_ONLY)
2992 2992
2993 @cpython_only
2993 def test_signature_parameter_implicit(self): 2994 def test_signature_parameter_implicit(self):
2994 with self.assertRaisesRegex(ValueError, 2995 with self.assertRaisesRegex(ValueError,
2995 'implicit arguments must be passed in as'): 2996 'implicit arguments must be passed in as'):
2996 inspect.Parameter('.0', kind=inspect.Parameter.POSITIONAL_ONLY) 2997 inspect.Parameter('.0', kind=inspect.Parameter.POSITIONAL_ONLY)
2997 2998
2998 param = inspect.Parameter( 2999 param = inspect.Parameter(
2999 '.0', kind=inspect.Parameter.POSITIONAL_OR_KEYWORD) 3000 '.0', kind=inspect.Parameter.POSITIONAL_OR_KEYWORD)
3000 self.assertEqual(param.kind, inspect.Parameter.POSITIONAL_ONLY) 3001 self.assertEqual(param.kind, inspect.Parameter.POSITIONAL_ONLY)
3001 self.assertEqual(param.name, 'implicit0') 3002 self.assertEqual(param.name, 'implicit0')
3002 3003
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
3241 sig.bind(a=0, args=1) 3242 sig.bind(a=0, args=1)
3242 3243
3243 def test(*args, **kwargs): 3244 def test(*args, **kwargs):
3244 return args, kwargs 3245 return args, kwargs
3245 self.assertEqual(self.call(test, args=1), ((), {'args': 1})) 3246 self.assertEqual(self.call(test, args=1), ((), {'args': 1}))
3246 3247
3247 sig = inspect.signature(test) 3248 sig = inspect.signature(test)
3248 ba = sig.bind(args=1) 3249 ba = sig.bind(args=1)
3249 self.assertEqual(ba.arguments, {'kwargs': {'args': 1}}) 3250 self.assertEqual(ba.arguments, {'kwargs': {'args': 1}})
3250 3251
3252 @cpython_only
3251 def test_signature_bind_implicit_arg(self): 3253 def test_signature_bind_implicit_arg(self):
3252 # Issue #19611: getcallargs should work with set comprehensions 3254 # Issue #19611: getcallargs should work with set comprehensions
3253 def make_set(): 3255 def make_set():
3254 return {z * z for z in range(5)} 3256 return {z * z for z in range(5)}
3255 setcomp_code = make_set.__code__.co_consts[1] 3257 setcomp_code = make_set.__code__.co_consts[1]
3256 setcomp_func = types.FunctionType(setcomp_code, {}) 3258 setcomp_func = types.FunctionType(setcomp_code, {})
3257 3259
3258 iterator = iter(range(5)) 3260 iterator = iter(range(5))
3259 self.assertEqual(self.call(setcomp_func, iterator), {0, 1, 4, 9, 16}) 3261 self.assertEqual(self.call(setcomp_func, iterator), {0, 1, 4, 9, 16})
3260 3262
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
3617 TestGetcallargsUnboundMethods, TestGetattrStatic, TestGetGeneratorState, 3619 TestGetcallargsUnboundMethods, TestGetattrStatic, TestGetGeneratorState,
3618 TestNoEOL, TestSignatureObject, TestSignatureBind, TestParameterObject, 3620 TestNoEOL, TestSignatureObject, TestSignatureBind, TestParameterObject,
3619 TestBoundArguments, TestSignaturePrivateHelpers, 3621 TestBoundArguments, TestSignaturePrivateHelpers,
3620 TestSignatureDefinitions, 3622 TestSignatureDefinitions,
3621 TestGetClosureVars, TestUnwrap, TestMain, TestReload, 3623 TestGetClosureVars, TestUnwrap, TestMain, TestReload,
3622 TestGetCoroutineState 3624 TestGetCoroutineState
3623 ) 3625 )
3624 3626
3625 if __name__ == "__main__": 3627 if __name__ == "__main__":
3626 test_main() 3628 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+