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

Side by Side Diff: Lib/inspect.py

Issue 20691: inspect.signature: Consider exposing 'follow_wrapper_chains' option in public API
Patch Set: Created 4 years, 4 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 | « Doc/library/inspect.rst ('k') | Lib/test/test_inspect.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Get useful information from live Python objects. 1 """Get useful information from live Python objects.
2 2
3 This module encapsulates the interface provided by the internal special 3 This module encapsulates the interface provided by the internal special
4 attributes (co_*, im_*, tb_*, etc.) in a friendlier fashion. 4 attributes (co_*, im_*, tb_*, etc.) in a friendlier fashion.
5 It also provides some help for examining source code and class layout. 5 It also provides some help for examining source code and class layout.
6 6
7 Here are some of the useful functions provided by this module: 7 Here are some of the useful functions provided by this module:
8 8
9 ismodule(), isclass(), ismethod(), isfunction(), isgeneratorfunction(), 9 ismodule(), isclass(), ismethod(), isfunction(), isgeneratorfunction(),
10 isgenerator(), istraceback(), isframe(), iscode(), isbuiltin(), 10 isgenerator(), istraceback(), isframe(), iscode(), isbuiltin(),
(...skipping 2646 matching lines...) Expand 10 before | Expand all | Expand 10 after
2657 return cls(parameters, 2657 return cls(parameters,
2658 return_annotation=annotations.get('return', _empty), 2658 return_annotation=annotations.get('return', _empty),
2659 __validate_parameters__=is_duck_function) 2659 __validate_parameters__=is_duck_function)
2660 2660
2661 @classmethod 2661 @classmethod
2662 def from_builtin(cls, func): 2662 def from_builtin(cls, func):
2663 """Constructs Signature for the given builtin function.""" 2663 """Constructs Signature for the given builtin function."""
2664 return _signature_from_builtin(cls, func) 2664 return _signature_from_builtin(cls, func)
2665 2665
2666 @classmethod 2666 @classmethod
2667 def from_callable(cls, obj): 2667 def from_callable(cls, obj, *, follow_wrapped=True):
2668 """Constructs Signature for the given callable object.""" 2668 """Constructs Signature for the given callable object."""
2669 return _signature_from_callable(obj, sigcls=cls) 2669 return _signature_from_callable(obj, sigcls=cls,
2670 follow_wrapper_chains=follow_wrapped)
2670 2671
2671 @property 2672 @property
2672 def parameters(self): 2673 def parameters(self):
2673 return self._parameters 2674 return self._parameters
2674 2675
2675 @property 2676 @property
2676 def return_annotation(self): 2677 def return_annotation(self):
2677 return self._return_annotation 2678 return self._return_annotation
2678 2679
2679 def replace(self, *, parameters=_void, return_annotation=_void): 2680 def replace(self, *, parameters=_void, return_annotation=_void):
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
2908 2909
2909 rendered = '({})'.format(', '.join(result)) 2910 rendered = '({})'.format(', '.join(result))
2910 2911
2911 if self.return_annotation is not _empty: 2912 if self.return_annotation is not _empty:
2912 anno = formatannotation(self.return_annotation) 2913 anno = formatannotation(self.return_annotation)
2913 rendered += ' -> {}'.format(anno) 2914 rendered += ' -> {}'.format(anno)
2914 2915
2915 return rendered 2916 return rendered
2916 2917
2917 2918
2918 def signature(obj): 2919 def signature(obj, *, follow_wrapped=True):
2919 """Get a signature object for the passed callable.""" 2920 """Get a signature object for the passed callable."""
2920 return Signature.from_callable(obj) 2921 return Signature.from_callable(obj, follow_wrapped=follow_wrapped)
2921 2922
2922 2923
2923 def _main(): 2924 def _main():
2924 """ Logic for inspecting an object given at command line """ 2925 """ Logic for inspecting an object given at command line """
2925 import argparse 2926 import argparse
2926 import importlib 2927 import importlib
2927 2928
2928 parser = argparse.ArgumentParser() 2929 parser = argparse.ArgumentParser()
2929 parser.add_argument( 2930 parser.add_argument(
2930 'object', 2931 'object',
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2973 else: 2974 else:
2974 print('Line: {}'.format(lineno)) 2975 print('Line: {}'.format(lineno))
2975 2976
2976 print('\n') 2977 print('\n')
2977 else: 2978 else:
2978 print(getsource(obj)) 2979 print(getsource(obj))
2979 2980
2980 2981
2981 if __name__ == "__main__": 2982 if __name__ == "__main__":
2982 _main() 2983 _main()
OLDNEW
« no previous file with comments | « Doc/library/inspect.rst ('k') | Lib/test/test_inspect.py » ('j') | no next file with comments »

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