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

Side by Side Diff: Lib/test/test_inspect.py

Issue 20334: make inspect Signature hashable
Patch Set: Created 5 years, 3 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:
View unified diff | Download patch
« no previous file with comments | « Lib/inspect.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2517 matching lines...) Expand 10 before | Expand all | Expand 10 after
2528 self.assertEqual(self.signature((lambda a=10: a)), 2528 self.assertEqual(self.signature((lambda a=10: a)),
2529 ((('a', 10, ..., "positional_or_keyword"),), 2529 ((('a', 10, ..., "positional_or_keyword"),),
2530 ...)) 2530 ...))
2531 2531
2532 def test_signature_equality(self): 2532 def test_signature_equality(self):
2533 def foo(a, *, b:int) -> float: pass 2533 def foo(a, *, b:int) -> float: pass
2534 self.assertNotEqual(inspect.signature(foo), 42) 2534 self.assertNotEqual(inspect.signature(foo), 42)
2535 2535
2536 def bar(a, *, b:int) -> float: pass 2536 def bar(a, *, b:int) -> float: pass
2537 self.assertEqual(inspect.signature(foo), inspect.signature(bar)) 2537 self.assertEqual(inspect.signature(foo), inspect.signature(bar))
2538 self.assertEqual(
2539 hash(inspect.signature(foo)), hash(inspect.signature(bar)))
2538 2540
2539 def bar(a, *, b:int) -> int: pass 2541 def bar(a, *, b:int) -> int: pass
2540 self.assertNotEqual(inspect.signature(foo), inspect.signature(bar)) 2542 self.assertNotEqual(inspect.signature(foo), inspect.signature(bar))
2543 self.assertNotEqual(
2544 hash(inspect.signature(foo)), hash(inspect.signature(bar)))
2541 2545
2542 def bar(a, *, b:int): pass 2546 def bar(a, *, b:int): pass
2543 self.assertNotEqual(inspect.signature(foo), inspect.signature(bar)) 2547 self.assertNotEqual(inspect.signature(foo), inspect.signature(bar))
2548 self.assertNotEqual(
2549 hash(inspect.signature(foo)), hash(inspect.signature(bar)))
2544 2550
2545 def bar(a, *, b:int=42) -> float: pass 2551 def bar(a, *, b:int=42) -> float: pass
2546 self.assertNotEqual(inspect.signature(foo), inspect.signature(bar)) 2552 self.assertNotEqual(inspect.signature(foo), inspect.signature(bar))
2553 self.assertNotEqual(
2554 hash(inspect.signature(foo)), hash(inspect.signature(bar)))
2547 2555
2548 def bar(a, *, c) -> float: pass 2556 def bar(a, *, c) -> float: pass
2549 self.assertNotEqual(inspect.signature(foo), inspect.signature(bar)) 2557 self.assertNotEqual(inspect.signature(foo), inspect.signature(bar))
2558 self.assertNotEqual(
2559 hash(inspect.signature(foo)), hash(inspect.signature(bar)))
2550 2560
2551 def bar(a, b:int) -> float: pass 2561 def bar(a, b:int) -> float: pass
2552 self.assertNotEqual(inspect.signature(foo), inspect.signature(bar)) 2562 self.assertNotEqual(inspect.signature(foo), inspect.signature(bar))
2563 self.assertNotEqual(
2564 hash(inspect.signature(foo)), hash(inspect.signature(bar)))
2553 def spam(b:int, a) -> float: pass 2565 def spam(b:int, a) -> float: pass
2554 self.assertNotEqual(inspect.signature(spam), inspect.signature(bar)) 2566 self.assertNotEqual(inspect.signature(spam), inspect.signature(bar))
2567 self.assertNotEqual(
2568 hash(inspect.signature(spam)), hash(inspect.signature(bar)))
2555 2569
2556 def foo(*, a, b, c): pass 2570 def foo(*, a, b, c): pass
2557 def bar(*, c, b, a): pass 2571 def bar(*, c, b, a): pass
2558 self.assertEqual(inspect.signature(foo), inspect.signature(bar)) 2572 self.assertEqual(inspect.signature(foo), inspect.signature(bar))
2573 self.assertEqual(
2574 hash(inspect.signature(foo)), hash(inspect.signature(bar)))
2559 2575
2560 def foo(*, a=1, b, c): pass 2576 def foo(*, a=1, b, c): pass
2561 def bar(*, c, b, a=1): pass 2577 def bar(*, c, b, a=1): pass
2562 self.assertEqual(inspect.signature(foo), inspect.signature(bar)) 2578 self.assertEqual(inspect.signature(foo), inspect.signature(bar))
2579 self.assertEqual(
2580 hash(inspect.signature(foo)), hash(inspect.signature(bar)))
2563 2581
2564 def foo(pos, *, a=1, b, c): pass 2582 def foo(pos, *, a=1, b, c): pass
2565 def bar(pos, *, c, b, a=1): pass 2583 def bar(pos, *, c, b, a=1): pass
2566 self.assertEqual(inspect.signature(foo), inspect.signature(bar)) 2584 self.assertEqual(inspect.signature(foo), inspect.signature(bar))
2585 self.assertEqual(
2586 hash(inspect.signature(foo)), hash(inspect.signature(bar)))
2567 2587
2568 def foo(pos, *, a, b, c): pass 2588 def foo(pos, *, a, b, c): pass
2569 def bar(pos, *, c, b, a=1): pass 2589 def bar(pos, *, c, b, a=1): pass
2570 self.assertNotEqual(inspect.signature(foo), inspect.signature(bar)) 2590 self.assertNotEqual(inspect.signature(foo), inspect.signature(bar))
2591 self.assertNotEqual(
2592 hash(inspect.signature(foo)), hash(inspect.signature(bar)))
2571 2593
2572 def foo(pos, *args, a=42, b, c, **kwargs:int): pass 2594 def foo(pos, *args, a=42, b, c, **kwargs:int): pass
2573 def bar(pos, *args, c, b, a=42, **kwargs:int): pass 2595 def bar(pos, *args, c, b, a=42, **kwargs:int): pass
2574 self.assertEqual(inspect.signature(foo), inspect.signature(bar)) 2596 self.assertEqual(inspect.signature(foo), inspect.signature(bar))
2597 self.assertEqual(
2598 hash(inspect.signature(foo)), hash(inspect.signature(bar)))
2575 2599
2576 def test_signature_hashable(self): 2600 def test_signature_hashable(self):
2577 S = inspect.Signature 2601 S = inspect.Signature
2578 P = inspect.Parameter 2602 P = inspect.Parameter
2579 2603
2580 def foo(a): pass 2604 def foo(a): pass
2581 foo_sig = inspect.signature(foo) 2605 foo_sig = inspect.signature(foo)
2582 2606
2583 manual_sig = S(parameters=[P('a', P.POSITIONAL_OR_KEYWORD)]) 2607 manual_sig = S(parameters=[P('a', P.POSITIONAL_OR_KEYWORD)])
2584 2608
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
3242 TestInterpreterStack, TestClassesAndFunctions, TestPredicates, 3266 TestInterpreterStack, TestClassesAndFunctions, TestPredicates,
3243 TestGetcallargsFunctions, TestGetcallargsMethods, 3267 TestGetcallargsFunctions, TestGetcallargsMethods,
3244 TestGetcallargsUnboundMethods, TestGetattrStatic, TestGetGeneratorState, 3268 TestGetcallargsUnboundMethods, TestGetattrStatic, TestGetGeneratorState,
3245 TestNoEOL, TestSignatureObject, TestSignatureBind, TestParameterObject, 3269 TestNoEOL, TestSignatureObject, TestSignatureBind, TestParameterObject,
3246 TestBoundArguments, TestSignaturePrivateHelpers, TestGetClosureVars, 3270 TestBoundArguments, TestSignaturePrivateHelpers, TestGetClosureVars,
3247 TestUnwrap, TestMain 3271 TestUnwrap, TestMain
3248 ) 3272 )
3249 3273
3250 if __name__ == "__main__": 3274 if __name__ == "__main__":
3251 test_main() 3275 test_main()
OLDNEW
« no previous file with comments | « Lib/inspect.py ('k') | no next file » | no next file with comments »

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