Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb1aa263

Browse files
type args.py
1 parent1ad2ba4 commitb1aa263

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

‎bpython/args.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@
2121
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
# THE SOFTWARE.
2323

24+
# To gradually migrate to mypy we aren't setting these globally yet
25+
# mypy: disallow_untyped_defs=True
26+
# mypy: disallow_untyped_calls=True
27+
2428
"""
2529
Module to handle command line argument parsing, for all front-ends.
2630
"""
2731

2832
importargparse
29-
fromtypingimportTuple
33+
fromtypingimportTuple,List,Optional,NoReturn,Callable
34+
importcode
3035
importcurtsies
3136
importcwcwidth
3237
importgreenlet
@@ -50,11 +55,11 @@ class ArgumentParserFailed(ValueError):
5055

5156

5257
classRaisingArgumentParser(argparse.ArgumentParser):
53-
deferror(self,msg):
58+
deferror(self,msg:str)->NoReturn:
5459
raiseArgumentParserFailed()
5560

5661

57-
defversion_banner(base="bpython")->str:
62+
defversion_banner(base:str="bpython")->str:
5863
return_("{} version {} on top of Python {} {}").format(
5964
base,
6065
__version__,
@@ -67,7 +72,14 @@ def copyright_banner() -> str:
6772
return_("{} See AUTHORS.rst for details.").format(__copyright__)
6873

6974

70-
defparse(args,extras=None,ignore_stdin=False)->Tuple:
75+
Options=Tuple[str,str,Callable[[argparse._ArgumentGroup],None]]
76+
77+
78+
defparse(
79+
args:Optional[List[str]],
80+
extras:Options=None,
81+
ignore_stdin:bool=False,
82+
)->Tuple:
7183
"""Receive an argument list - if None, use sys.argv - parse all args and
7284
take appropriate action. Also receive optional extra argument: this should
7385
be a tuple of (title, description, callback)
@@ -214,7 +226,9 @@ def callback(group):
214226
returnConfig(options.config),options,options.args
215227

216228

217-
defexec_code(interpreter,args):
229+
defexec_code(
230+
interpreter:code.InteractiveInterpreter,args:List[str]
231+
)->None:
218232
"""
219233
Helper to execute code in a given interpreter, e.g. to implement the behavior of python3 [-i] file.py
220234
@@ -230,9 +244,10 @@ def exec_code(interpreter, args):
230244
old_argv,sys.argv=sys.argv,args
231245
sys.path.insert(0,os.path.abspath(os.path.dirname(args[0])))
232246
spec=importlib.util.spec_from_loader("__console__",loader=None)
247+
assertspec
233248
mod=importlib.util.module_from_spec(spec)
234249
sys.modules["__console__"]=mod
235-
interpreter.locals.update(mod.__dict__)
236-
interpreter.locals["__file__"]=args[0]
250+
interpreter.locals.update(mod.__dict__)# type: ignore # TODO use a more specific type that has a .locals attribute
251+
interpreter.locals["__file__"]=args[0]# type: ignore # TODO use a more specific type that has a .locals attribute
237252
interpreter.runsource(source,args[0],"exec")
238253
sys.argv=old_argv

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp