| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| def f(x: undefined): | ||
| pass |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from annotationlib import Format, ForwardRef | ||
| import asyncio | ||
| import builtins | ||
| import collections | ||
| Expand All | @@ -22,7 +23,6 @@ | |
| import types | ||
| import tempfile | ||
| import textwrap | ||
| from typing import Unpack | ||
| import unicodedata | ||
| import unittest | ||
| import unittest.mock | ||
| Expand All | @@ -46,6 +46,7 @@ | |
| from test.test_inspect import inspect_fodder as mod | ||
| from test.test_inspect import inspect_fodder2 as mod2 | ||
| from test.test_inspect import inspect_stringized_annotations | ||
| from test.test_inspect import inspect_deferred_annotations | ||
|
|
||
|
|
||
| # Functions tested in this suite: | ||
| Expand Down Expand Up | @@ -4622,6 +4623,18 @@ def func( | |
| expected_multiline, | ||
| ) | ||
|
|
||
| def test_signature_format_unquote(self): | ||
| def func(x: 'int') -> 'str': ... | ||
|
|
||
| self.assertEqual( | ||
| inspect.signature(func).format(), | ||
| "(x: 'int') -> 'str'" | ||
| ) | ||
| self.assertEqual( | ||
| inspect.signature(func).format(quote_annotation_strings=False), | ||
| "(x: int) -> str" | ||
| ) | ||
|
|
||
| def test_signature_replace_parameters(self): | ||
| def test(a, b) -> 42: | ||
| pass | ||
| Expand Down Expand Up | @@ -4854,6 +4867,26 @@ def test_signature_eval_str(self): | |
| par('b', PORK, annotation=tuple), | ||
| ))) | ||
|
|
||
| def test_signature_annotation_format(self): | ||
| ida = inspect_deferred_annotations | ||
| sig = inspect.Signature | ||
| par = inspect.Parameter | ||
| PORK = inspect.Parameter.POSITIONAL_OR_KEYWORD | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality🐷
Sorry, something went wrong.
AlexWaygood and efimov-mikhail reacted with heart emoji
All reactions
|
||
| for signature_func in (inspect.signature, inspect.Signature.from_callable): | ||
| with self.subTest(signature_func=signature_func): | ||
| self.assertEqual( | ||
| signature_func(ida.f, annotation_format=Format.STRING), | ||
| sig([par("x", PORK, annotation="undefined")]) | ||
| ) | ||
| self.assertEqual( | ||
| signature_func(ida.f, annotation_format=Format.FORWARDREF), | ||
| sig([par("x", PORK, annotation=ForwardRef("undefined"))]) | ||
| ) | ||
| with self.assertRaisesRegex(NameError, "undefined"): | ||
| signature_func(ida.f, annotation_format=Format.VALUE) | ||
| with self.assertRaisesRegex(NameError, "undefined"): | ||
| signature_func(ida.f) | ||
|
|
||
| def test_signature_none_annotation(self): | ||
| class funclike: | ||
| # Has to be callable, and have correct | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Add an *annoation_format* parameter to :func:`inspect.signature`. Add an | ||
| *quote_annotation_strings* parameter to :meth:`inspect.Signature.format`. Use the | ||
| new functionality to improve the display of annotations in signatures in | ||
| :mod:`pydoc`. Patch by Jelle Zijlstra. |
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.