| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1ce68f6 commit dc441ef
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2074,13 +2074,11 @@ def _signature_is_functionlike(obj): | |||
| 2074 | 2074 | code = getattr(obj, '__code__', None) | |
| 2075 | 2075 | defaults = getattr(obj, '__defaults__', _void) # Important to use _void ... | |
| 2076 | 2076 | kwdefaults = getattr(obj, '__kwdefaults__', _void) # ... and not None here | |
| 2077 | - annotations = getattr(obj, '__annotations__', None) | ||
| 2078 | 2077 | ||
| 2079 | 2078 | return (isinstance(code, types.CodeType) and | |
| 2080 | 2079 | isinstance(name, str) and | |
| 2081 | 2080 | (defaults is None or isinstance(defaults, tuple)) and | |
| 2082 | - (kwdefaults is None or isinstance(kwdefaults, dict)) and | ||
| 2083 | - (isinstance(annotations, (dict)) or annotations is None) ) | ||
| 2081 | + (kwdefaults is None or isinstance(kwdefaults, dict))) | ||
| 2084 | 2082 | ||
| 2085 | 2083 | ||
| 2086 | 2084 | def _signature_strip_non_python_syntax(signature): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4997,6 +4997,37 @@ def test_signature_annotation_format(self): | |||
| 4997 | 4997 | with self.assertRaisesRegex(NameError, "undefined"): | |
| 4998 | 4998 | signature_func(ida.f) | |
| 4999 | 4999 | ||
| 5000 | + def test_signature_deferred_annotations(self): | ||
| 5001 | + def f(x: undef): | ||
| 5002 | + pass | ||
| 5003 | + | ||
| 5004 | + class C: | ||
| 5005 | + x: undef | ||
| 5006 | + | ||
| 5007 | + def __init__(self, x: undef): | ||
| 5008 | + self.x = x | ||
| 5009 | + | ||
| 5010 | + sig = inspect.signature(f, annotation_format=Format.FORWARDREF) | ||
| 5011 | + self.assertEqual(list(sig.parameters), ['x']) | ||
| 5012 | + sig = inspect.signature(C, annotation_format=Format.FORWARDREF) | ||
| 5013 | + self.assertEqual(list(sig.parameters), ['x']) | ||
| 5014 | + | ||
| 5015 | + class CallableWrapper: | ||
| 5016 | + def __init__(self, func): | ||
| 5017 | + self.func = func | ||
| 5018 | + self.__annotate__ = func.__annotate__ | ||
| 5019 | + | ||
| 5020 | + def __call__(self, *args, **kwargs): | ||
| 5021 | + return self.func(*args, **kwargs) | ||
| 5022 | + | ||
| 5023 | + @property | ||
| 5024 | + def __annotations__(self): | ||
| 5025 | + return self.__annotate__(Format.VALUE) | ||
| 5026 | + | ||
| 5027 | + cw = CallableWrapper(f) | ||
| 5028 | + sig = inspect.signature(cw, annotation_format=Format.FORWARDREF) | ||
| 5029 | + self.assertEqual(list(sig.parameters), ['args', 'kwargs']) | ||
| 5030 | + | ||
| 5000 | 5031 | def test_signature_none_annotation(self): | |
| 5001 | 5032 | class funclike: | |
| 5002 | 5033 | # Has to be callable, and have correct | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Avoid accessing ``__annotations__`` unnecessarily in | ||
| 2 | + :func:`inspect.signature`. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments