Show More
@@ -12,6 +12,8 b' import sys' | |||||
12 | from IPython.core.magic_arguments import (argument, argument_group, kwds, |
|
12 | from IPython.core.magic_arguments import (argument, argument_group, kwds, | |
13 | magic_arguments, parse_argstring, real_name) |
|
13 | magic_arguments, parse_argstring, real_name) | |
14 |
|
14 | |||
|
15 | LEADING_SPACE = "" if sys.version_info > (3, 13) else " " | |||
|
16 | ||||
15 |
|
17 | |||
16 | @magic_arguments() |
|
18 | @magic_arguments() | |
17 | @argument('-f', '--foo', help="an argument") |
|
19 | @argument('-f', '--foo', help="an argument") | |
@@ -81,14 +83,14 b' def test_magic_arguments():' | |||||
81 |
|
83 | |||
82 | assert ( |
|
84 | assert ( | |
83 | magic_foo1.__doc__ |
|
85 | magic_foo1.__doc__ | |
84 |
== f"::\n\n %foo1 [-f FOO]\n\n |
|
86 | == f"::\n\n %foo1 [-f FOO]\n\n{LEADING_SPACE}A docstring.\n\n{options}:\n -f FOO, --foo FOO an argument\n" | |
85 | ) |
|
87 | ) | |
86 | assert getattr(magic_foo1, "argcmd_name", None) == None |
|
88 | assert getattr(magic_foo1, "argcmd_name", None) == None | |
87 | assert real_name(magic_foo1) == "foo1" |
|
89 | assert real_name(magic_foo1) == "foo1" | |
88 | assert magic_foo1(None, "") == argparse.Namespace(foo=None) |
|
90 | assert magic_foo1(None, "") == argparse.Namespace(foo=None) | |
89 | assert hasattr(magic_foo1, "has_arguments") |
|
91 | assert hasattr(magic_foo1, "has_arguments") | |
90 |
|
92 | |||
91 |
assert magic_foo2.__doc__ == "::\n\n %foo2\n\n |
|
93 | assert magic_foo2.__doc__ == f"::\n\n %foo2\n\n{LEADING_SPACE}A docstring.\n" | |
92 | assert getattr(magic_foo2, "argcmd_name", None) == None |
|
94 | assert getattr(magic_foo2, "argcmd_name", None) == None | |
93 | assert real_name(magic_foo2) == "foo2" |
|
95 | assert real_name(magic_foo2) == "foo2" | |
94 | assert magic_foo2(None, "") == argparse.Namespace() |
|
96 | assert magic_foo2(None, "") == argparse.Namespace() | |
@@ -96,7 +98,7 b' def test_magic_arguments():' | |||||
96 |
|
98 | |||
97 | assert ( |
|
99 | assert ( | |
98 | magic_foo3.__doc__ |
|
100 | magic_foo3.__doc__ | |
99 |
== f"::\n\n %foo3 [-f FOO] [-b BAR] [-z BAZ]\n\n |
|
101 | == f"::\n\n %foo3 [-f FOO] [-b BAR] [-z BAZ]\n\n{LEADING_SPACE}A docstring.\n\n{options}:\n -f FOO, --foo FOO an argument\n\nGroup:\n -b BAR, --bar BAR a grouped argument\n\nSecond Group:\n -z BAZ, --baz BAZ another grouped argument\n" | |
100 | ) |
|
102 | ) | |
101 | assert getattr(magic_foo3, "argcmd_name", None) == None |
|
103 | assert getattr(magic_foo3, "argcmd_name", None) == None | |
102 | assert real_name(magic_foo3) == "foo3" |
|
104 | assert real_name(magic_foo3) == "foo3" | |
@@ -105,7 +107,7 b' def test_magic_arguments():' | |||||
105 |
|
107 | |||
106 | assert ( |
|
108 | assert ( | |
107 | magic_foo4.__doc__ |
|
109 | magic_foo4.__doc__ | |
108 |
== f"::\n\n %foo4 [-f FOO]\n\n |
|
110 | == f"::\n\n %foo4 [-f FOO]\n\n{LEADING_SPACE}A docstring.\n\n{options}:\n -f FOO, --foo FOO an argument\n" | |
109 | ) |
|
111 | ) | |
110 | assert getattr(magic_foo4, "argcmd_name", None) == None |
|
112 | assert getattr(magic_foo4, "argcmd_name", None) == None | |
111 | assert real_name(magic_foo4) == "foo4" |
|
113 | assert real_name(magic_foo4) == "foo4" | |
@@ -114,7 +116,7 b' def test_magic_arguments():' | |||||
114 |
|
116 | |||
115 | assert ( |
|
117 | assert ( | |
116 | magic_foo5.__doc__ |
|
118 | magic_foo5.__doc__ | |
117 |
== f"::\n\n %frobnicate [-f FOO]\n\n |
|
119 | == f"::\n\n %frobnicate [-f FOO]\n\n{LEADING_SPACE}A docstring.\n\n{options}:\n -f FOO, --foo FOO an argument\n" | |
118 | ) |
|
120 | ) | |
119 | assert getattr(magic_foo5, "argcmd_name", None) == "frobnicate" |
|
121 | assert getattr(magic_foo5, "argcmd_name", None) == "frobnicate" | |
120 | assert real_name(magic_foo5) == "frobnicate" |
|
122 | assert real_name(magic_foo5) == "frobnicate" | |
@@ -123,7 +125,7 b' def test_magic_arguments():' | |||||
123 |
|
125 | |||
124 | assert ( |
|
126 | assert ( | |
125 | magic_magic_foo.__doc__ |
|
127 | magic_magic_foo.__doc__ | |
126 |
== f"::\n\n %magic_foo [-f FOO]\n\n |
|
128 | == f"::\n\n %magic_foo [-f FOO]\n\n{LEADING_SPACE}A docstring.\n\n{options}:\n -f FOO, --foo FOO an argument\n" | |
127 | ) |
|
129 | ) | |
128 | assert getattr(magic_magic_foo, "argcmd_name", None) == None |
|
130 | assert getattr(magic_magic_foo, "argcmd_name", None) == None | |
129 | assert real_name(magic_magic_foo) == "magic_foo" |
|
131 | assert real_name(magic_magic_foo) == "magic_foo" | |
@@ -132,7 +134,7 b' def test_magic_arguments():' | |||||
132 |
|
134 | |||
133 | assert ( |
|
135 | assert ( | |
134 | foo.__doc__ |
|
136 | foo.__doc__ | |
135 |
== f"::\n\n %foo [-f FOO]\n\n |
|
137 | == f"::\n\n %foo [-f FOO]\n\n{LEADING_SPACE}A docstring.\n\n{options}:\n -f FOO, --foo FOO an argument\n" | |
136 | ) |
|
138 | ) | |
137 | assert getattr(foo, "argcmd_name", None) == None |
|
139 | assert getattr(foo, "argcmd_name", None) == None | |
138 | assert real_name(foo) == "foo" |
|
140 | assert real_name(foo) == "foo" |
@@ -17,7 +17,7 b' import warnings' | |||||
17 | from string import Formatter |
|
17 | from string import Formatter | |
18 | from pathlib import Path |
|
18 | from pathlib import Path | |
19 |
|
19 | |||
20 |
from typing import List, |
|
20 | from typing import List, Dict, Tuple | |
21 |
|
21 | |||
22 |
|
22 | |||
23 | class LSString(str): |
|
23 | class LSString(str): | |
@@ -357,7 +357,7 b' def format_screen(strng):' | |||||
357 | return strng |
|
357 | return strng | |
358 |
|
358 | |||
359 |
|
359 | |||
360 | def dedent(text): |
|
360 | def dedent(text: str) -> str: | |
361 | """Equivalent of textwrap.dedent that ignores unindented first line. |
|
361 | """Equivalent of textwrap.dedent that ignores unindented first line. | |
362 |
|
362 | |||
363 | This means it will still dedent strings like: |
|
363 | This means it will still dedent strings like: |
General Comments 0
You need to be logged in to leave comments.
Login now