FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-132493: Avoid eager evaluation of annotations in `@reprlib.recursive_repr()` by JelleZijlstra · Pull Request #133411 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion Lib/reprlib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def wrapper(self):
wrapper.__doc__ = getattr(user_function, '__doc__')
wrapper.__name__ = getattr(user_function, '__name__')
wrapper.__qualname__ = getattr(user_function, '__qualname__')
wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
wrapper.__annotate__ = getattr(user_function, '__annotate__', None)
wrapper.__type_params__ = getattr(user_function, '__type_params__', ())
wrapper.__wrapped__ = user_function
return wrapper
Expand Down
17 changes: 16 additions & 1 deletion Lib/test/test_reprlib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Nick Mathewson
"""

import annotationlib
import sys
import os
import shutil
Expand All @@ -11,7 +12,7 @@
import unittest
import textwrap

from test.support import verbose
from test.support import verbose, EqualToForwardRef
from test.support.os_helper import create_empty_file
from reprlib import repr as r # Don't shadow builtin repr
from reprlib import Repr
Expand Down Expand Up @@ -829,5 +830,19 @@ def __repr__[T: str](self, default: T = '') -> str:
self.assertEqual(type_params[0].__name__, 'T')
self.assertEqual(type_params[0].__bound__, str)

def test_annotations(self):
class My:
@recursive_repr()
def __repr__(self, default: undefined = ...):
return default

annotations = annotationlib.get_annotations(
My.__repr__, format=annotationlib.Format.FORWARDREF
)
self.assertEqual(
annotations,
{'default': EqualToForwardRef("undefined", owner=My.__repr__)}
)

if __name__ == "__main__":
unittest.main()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Avoid eagerly evaluating annotations in functions decorated with
:func:`reprlib.recursive_repr`.

Back | FazBrowse Home | New Git URL