| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,7 @@ def wrapper(self): | |||
| 28 | 28 | wrapper.__doc__ = getattr(user_function, '__doc__') | |
| 29 | 29 | wrapper.__name__ = getattr(user_function, '__name__') | |
| 30 | 30 | wrapper.__qualname__ = getattr(user_function, '__qualname__') | |
| 31 | - wrapper.__annotations__ = getattr(user_function, '__annotations__', {}) | ||
| 31 | + wrapper.__annotate__ = getattr(user_function, '__annotate__', None) | ||
| 32 | 32 | wrapper.__type_params__ = getattr(user_function, '__type_params__', ()) | |
| 33 | 33 | wrapper.__wrapped__ = user_function | |
| 34 | 34 | return wrapper | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | Nick Mathewson | |
| 4 | 4 | """ | |
| 5 | 5 | ||
| 6 | + import annotationlib | ||
| 6 | 7 | import sys | |
| 7 | 8 | import os | |
| 8 | 9 | import shutil | |
@@ -11,7 +12,7 @@ | |||
| 11 | 12 | import unittest | |
| 12 | 13 | import textwrap | |
| 13 | 14 | ||
| 14 | - from test.support import verbose | ||
| 15 | + from test.support import verbose, EqualToForwardRef | ||
| 15 | 16 | from test.support.os_helper import create_empty_file | |
| 16 | 17 | from reprlib import repr as r # Don't shadow builtin repr | |
| 17 | 18 | from reprlib import Repr | |
@@ -829,5 +830,19 @@ def __repr__[T: str](self, default: T = '') -> str: | |||
| 829 | 830 | self.assertEqual(type_params[0].__name__, 'T') | |
| 830 | 831 | self.assertEqual(type_params[0].__bound__, str) | |
| 831 | 832 | ||
| 833 | + def test_annotations(self): | ||
| 834 | + class My: | ||
| 835 | + @recursive_repr() | ||
| 836 | + def __repr__(self, default: undefined = ...): | ||
| 837 | + return default | ||
| 838 | + | ||
| 839 | + annotations = annotationlib.get_annotations( | ||
| 840 | + My.__repr__, format=annotationlib.Format.FORWARDREF | ||
| 841 | + ) | ||
| 842 | + self.assertEqual( | ||
| 843 | + annotations, | ||
| 844 | + {'default': EqualToForwardRef("undefined", owner=My.__repr__)} | ||
| 845 | + ) | ||
| 846 | + | ||
| 832 | 847 | if __name__ == "__main__": | |
| 833 | 848 | unittest.main() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Avoid eagerly evaluating annotations in functions decorated with | ||
| 2 | + :func:`reprlib.recursive_repr`. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments