diff options
author | Kirill Podoprigora <kirill.bast9@mail.ru> | 2024-02-17 15:14:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-17 15:14:41 (GMT) |
commit | e32cde54f5b086bf994cb183f67d0b1a3a378c3e (patch) | |
tree | 3c70df5ccd03ceb3a0aeaef1ef7a490c2c49294d /Lib/test/test_pydoc/test_pydoc.py | |
parent | 6e89292f2c995f0708a9587efb0677166ab5fa55 (diff) | |
download | cpython-e32cde54f5b086bf994cb183f67d0b1a3a378c3e.zip cpython-e32cde54f5b086bf994cb183f67d0b1a3a378c3e.tar.gz cpython-e32cde54f5b086bf994cb183f67d0b1a3a378c3e.tar.bz2 |
[3.12] gh-107155: Fix help() for lambda function with return annotation (GH-115612)
(cherry picked from commit b9a9e3dd62326b726ad2e8e8efd87ca6327b4019)
Diffstat (limited to 'Lib/test/test_pydoc/test_pydoc.py')
-rw-r--r-- | Lib/test/test_pydoc/test_pydoc.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_pydoc/test_pydoc.py b/Lib/test/test_pydoc/test_pydoc.py index b1aa967..a35257c 100644 --- a/Lib/test/test_pydoc/test_pydoc.py +++ b/Lib/test/test_pydoc/test_pydoc.py @@ -691,6 +691,30 @@ class PydocDocTest(unittest.TestCase): finally: pydoc.getpager = getpager_old + def test_lambda_with_return_annotation(self): + func = lambda a, b, c: 1 + func.__annotations__ = {"return": int} + with captured_output('stdout') as help_io: + pydoc.help(func) + helptext = help_io.getvalue() + self.assertIn("lambda (a, b, c) -> int", helptext) + + def test_lambda_without_return_annotation(self): + func = lambda a, b, c: 1 + func.__annotations__ = {"a": int, "b": int, "c": int} + with captured_output('stdout') as help_io: + pydoc.help(func) + helptext = help_io.getvalue() + self.assertIn("lambda (a: int, b: int, c: int)", helptext) + + def test_lambda_with_return_and_params_annotation(self): + func = lambda a, b, c: 1 + func.__annotations__ = {"a": int, "b": int, "c": int, "return": int} + with captured_output('stdout') as help_io: + pydoc.help(func) + helptext = help_io.getvalue() + self.assertIn("lambda (a: int, b: int, c: int) -> int", helptext) + def test_namedtuple_fields(self): Person = namedtuple('Person', ['nickname', 'firstname']) with captured_stdout() as help_io: |