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

Commit110b97c

Browse files
gh-104050: Annotate toplevel functions in clinic.py (#106435)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent17af982 commit110b97c

File tree

1 file changed

+47
-16
lines changed

1 file changed

+47
-16
lines changed

‎Tools/clinic/clinic.py‎

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ def permute_optional_groups(left, required, right):
575575
returntuple(accumulator)
576576

577577

578-
defstrip_leading_and_trailing_blank_lines(s):
578+
defstrip_leading_and_trailing_blank_lines(s:str)->str:
579579
lines=s.rstrip().split('\n')
580580
whilelines:
581581
line=lines[0]
@@ -585,7 +585,11 @@ def strip_leading_and_trailing_blank_lines(s):
585585
return'\n'.join(lines)
586586

587587
@functools.lru_cache()
588-
defnormalize_snippet(s,*,indent=0):
588+
defnormalize_snippet(
589+
s:str,
590+
*,
591+
indent:int=0
592+
)->str:
589593
"""
590594
Reformats s:
591595
* removes leading and trailing blank lines
@@ -599,7 +603,11 @@ def normalize_snippet(s, *, indent=0):
599603
returns
600604

601605

602-
defdeclare_parser(f,*,hasformat=False):
606+
defdeclare_parser(
607+
f:Function,
608+
*,
609+
hasformat:bool=False
610+
)->str:
603611
"""
604612
Generates the code template for a static local PyArg_Parser variable,
605613
with an initializer. For core code (incl. builtin modules) the
@@ -658,7 +666,10 @@ def declare_parser(f, *, hasformat=False):
658666
returnnormalize_snippet(declarations)
659667

660668

661-
defwrap_declarations(text,length=78):
669+
defwrap_declarations(
670+
text:str,
671+
length:int=78
672+
)->str:
662673
"""
663674
A simple-minded text wrapper for C function declarations.
664675
@@ -680,14 +691,14 @@ def wrap_declarations(text, length=78):
680691
ifnotafter_l_paren:
681692
lines.append(line)
682693
continue
683-
parameters,_,after_r_paren=after_l_paren.partition(')')
694+
in_paren,_,after_r_paren=after_l_paren.partition(')')
684695
ifnot_:
685696
lines.append(line)
686697
continue
687-
if','notinparameters:
698+
if','notinin_paren:
688699
lines.append(line)
689700
continue
690-
parameters= [x.strip()+", "forxinparameters.split(',')]
701+
parameters= [x.strip()+", "forxinin_paren.split(',')]
691702
prefix+="("
692703
iflen(prefix)<length:
693704
spaces=" "*len(prefix)
@@ -1589,7 +1600,12 @@ def OverrideStdioWith(stdout):
15891600
sys.stdout=saved_stdout
15901601

15911602

1592-
defcreate_regex(before,after,word=True,whole_line=True):
1603+
defcreate_regex(
1604+
before:str,
1605+
after:str,
1606+
word:bool=True,
1607+
whole_line:bool=True
1608+
)->re.Pattern[str]:
15931609
"""Create an re object for matching marker lines."""
15941610
group_re=r"\w+"ifwordelse".+"
15951611
pattern=r'{}({}){}'
@@ -1985,7 +2001,7 @@ def file_changed(filename: str, new_contents: str) -> bool:
19852001
returnTrue
19862002

19872003

1988-
defwrite_file(filename:str,new_contents:str):
2004+
defwrite_file(filename:str,new_contents:str)->None:
19892005
# Atomic write using a temporary file and os.replace()
19902006
filename_new=f"{filename}.new"
19912007
withopen(filename_new,"w",encoding="utf-8")asfp:
@@ -2602,7 +2618,10 @@ def __getattribute__(self, name: str):
26022618
fail("Stepped on a land mine, trying to access attribute "+repr(name)+":\n"+self.__message__)
26032619

26042620

2605-
defadd_c_converter(f,name=None):
2621+
defadd_c_converter(
2622+
f:type[CConverter],
2623+
name:str|None=None
2624+
)->type[CConverter]:
26062625
ifnotname:
26072626
name=f.__name__
26082627
ifnotname.endswith('_converter'):
@@ -2620,7 +2639,10 @@ def add_default_legacy_c_converter(cls):
26202639
legacy_converters[cls.format_unit]=cls
26212640
returncls
26222641

2623-
defadd_legacy_c_converter(format_unit,**kwargs):
2642+
defadd_legacy_c_converter(
2643+
format_unit:str,
2644+
**kwargs
2645+
)->Callable[[ConverterType],ConverterType]:
26242646
"""
26252647
Adds a legacy converter.
26262648
"""
@@ -3887,7 +3909,9 @@ def parse_arg(self, argname: str, displayname: str) -> str:
38873909
returnsuper().parse_arg(argname,displayname)
38883910

38893911

3890-
defcorrect_name_for_self(f)->tuple[str,str]:
3912+
defcorrect_name_for_self(
3913+
f:Function
3914+
)->tuple[str,str]:
38913915
iff.kindin (CALLABLE,METHOD_INIT):
38923916
iff.cls:
38933917
return"PyObject *","self"
@@ -3898,7 +3922,9 @@ def correct_name_for_self(f) -> tuple[str, str]:
38983922
return"PyTypeObject *","type"
38993923
raiseRuntimeError("Unhandled type of function f: "+repr(f.kind))
39003924

3901-
defrequired_type_for_self_for_parser(f):
3925+
defrequired_type_for_self_for_parser(
3926+
f:Function
3927+
)->str|None:
39023928
type,_=correct_name_for_self(f)
39033929
iff.kindin (METHOD_INIT,METHOD_NEW,STATIC_METHOD,CLASS_METHOD):
39043930
returntype
@@ -4193,7 +4219,12 @@ class float_return_converter(double_return_converter):
41934219
cast='(double)'
41944220

41954221

4196-
defeval_ast_expr(node,globals,*,filename='-'):
4222+
defeval_ast_expr(
4223+
node:ast.expr,
4224+
globals:dict[str,Any],
4225+
*,
4226+
filename:str='-'
4227+
)->FunctionType:
41974228
"""
41984229
Takes an ast.Expr node. Compiles and evaluates it.
41994230
Returns the result of the expression.
@@ -4205,8 +4236,8 @@ def eval_ast_expr(node, globals, *, filename='-'):
42054236
ifisinstance(node,ast.Expr):
42064237
node=node.value
42074238

4208-
node=ast.Expression(node)
4209-
co=compile(node,filename,'eval')
4239+
expr=ast.Expression(node)
4240+
co=compile(expr,filename,'eval')
42104241
fn=FunctionType(co,globals)
42114242
returnfn()
42124243

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp