Skip to content

Commit 4ebc406

Browse files
committed
format
1 parent a3cb74c commit 4ebc406

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

Lib/annotationlib.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,19 +773,22 @@ def value_to_source(value):
773773
774774
"""
775775
if isinstance(value, type):
776-
if value.__module__ == 'builtins':
776+
if value.__module__ == "builtins":
777777
return value.__qualname__
778-
return f'{value.__module__}.{value.__qualname__}'
778+
return f"{value.__module__}.{value.__qualname__}"
779779
if value is ...:
780-
return '...'
780+
return "..."
781781
if isinstance(value, (types.FunctionType, types.BuiltinFunctionType)):
782782
return value.__name__
783783
return repr(value)
784784

785785

786786
def annotations_to_source(annotations):
787787
"""Convert an annotation dict containing values to approximately the SOURCE format."""
788-
return {n: t if isinstance(t, str) else value_to_source(t) for n, t in annotations.items()}
788+
return {
789+
n: t if isinstance(t, str) else value_to_source(t)
790+
for n, t in annotations.items()
791+
}
789792

790793

791794
def _get_and_call_annotate(obj, format):

Lib/test/test_annotationlib.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
import itertools
88
import pickle
99
import unittest
10-
from annotationlib import Format, ForwardRef, get_annotations, get_annotate_function, annotations_to_source, value_to_source
10+
from annotationlib import (
11+
Format,
12+
ForwardRef,
13+
get_annotations,
14+
get_annotate_function,
15+
annotations_to_source,
16+
value_to_source,
17+
)
1118
from typing import Unpack
1219

1320
from test import support
@@ -329,7 +336,10 @@ def test_name_lookup_without_eval(self):
329336
# namespaces without going through eval()
330337
self.assertIs(ForwardRef("int").evaluate(), int)
331338
self.assertIs(ForwardRef("int").evaluate(locals={"int": str}), str)
332-
self.assertIs(ForwardRef("int").evaluate(locals={"int": float}, globals={"int": str}), float)
339+
self.assertIs(
340+
ForwardRef("int").evaluate(locals={"int": float}, globals={"int": str}),
341+
float,
342+
)
333343
self.assertIs(ForwardRef("int").evaluate(globals={"int": str}), str)
334344
with support.swap_attr(builtins, "int", dict):
335345
self.assertIs(ForwardRef("int").evaluate(), dict)
@@ -1100,11 +1110,11 @@ def test_annotations_to_source(self):
11001110
self.assertEqual(annotations_to_source({}), {})
11011111
self.assertEqual(annotations_to_source({"x": int}), {"x": "int"})
11021112
self.assertEqual(annotations_to_source({"x": "int"}), {"x": "int"})
1103-
self.assertEqual(annotations_to_source({"x": int, "y": str}), {"x": "int", "y": "str"})
1113+
self.assertEqual(
1114+
annotations_to_source({"x": int, "y": str}), {"x": "int", "y": "str"}
1115+
)
11041116

11051117

11061118
class TestAnnotationLib(unittest.TestCase):
11071119
def test__all__(self):
11081120
support.check__all__(self, annotationlib)
1109-
1110-

0 commit comments

Comments
 (0)