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

Commita180e7a

Browse files
gh-104050: Argument clinic: Annotate theDestination class (#106655)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
1 parent357e9e9 commita180e7a

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

‎Tools/clinic/clinic.py‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,27 +1954,32 @@ def dump(self):
19541954
return"".join(texts)
19551955

19561956

1957+
@dc.dataclass(slots=True,repr=False)
19571958
classDestination:
1958-
def__init__(self,name,type,clinic,*args):
1959-
self.name=name
1960-
self.type=type
1961-
self.clinic=clinic
1962-
self.buffers=BufferSeries()
1959+
name:str
1960+
type:str
1961+
clinic:Clinic
1962+
buffers:BufferSeries=dc.field(init=False,default_factory=BufferSeries)
1963+
filename:str=dc.field(init=False)# set in __post_init__
19631964

1965+
args:dc.InitVar[tuple[str, ...]]= ()
1966+
1967+
def__post_init__(self,args:tuple[str, ...])->None:
19641968
valid_types= ('buffer','file','suppress')
1965-
iftypenotinvalid_types:
1969+
ifself.typenotinvalid_types:
19661970
fail(
1967-
f"Invalid destination type{type!r} for{name}, "
1971+
f"Invalid destination type{self.type!r} for{self.name}, "
19681972
f"must be{', '.join(valid_types)}"
19691973
)
1970-
extra_arguments=1iftype=="file"else0
1974+
extra_arguments=1ifself.type=="file"else0
19711975
iflen(args)<extra_arguments:
1972-
fail(f"Not enough arguments for destination{name} new{type}")
1976+
fail(f"Not enough arguments for destination{self.name} new{self.type}")
19731977
iflen(args)>extra_arguments:
1974-
fail(f"Too many arguments for destination{name} new{type}")
1975-
iftype=='file':
1978+
fail(f"Too many arguments for destination{self.name} new{self.type}")
1979+
ifself.type=='file':
19761980
d= {}
1977-
filename=clinic.filename
1981+
filename=self.clinic.filename
1982+
assertfilenameisnotNone
19781983
d['path']=filename
19791984
dirname,basename=os.path.split(filename)
19801985
ifnotdirname:
@@ -1984,19 +1989,19 @@ def __init__(self, name, type, clinic, *args):
19841989
d['basename_root'],d['basename_extension']=os.path.splitext(filename)
19851990
self.filename=args[0].format_map(d)
19861991

1987-
def__repr__(self):
1992+
def__repr__(self)->str:
19881993
ifself.type=='file':
19891994
file_repr=" "+repr(self.filename)
19901995
else:
19911996
file_repr=''
19921997
return"".join(("<Destination ",self.name," ",self.type,file_repr,">"))
19931998

1994-
defclear(self):
1999+
defclear(self)->None:
19952000
ifself.type!='buffer':
19962001
fail("Can't clear destination"+self.name+" , it's not of type buffer")
19972002
self.buffers.clear()
19982003

1999-
defdump(self):
2004+
defdump(self)->str:
20002005
returnself.buffers.dump()
20012006

20022007

@@ -2164,11 +2169,11 @@ def add_destination(
21642169
self,
21652170
name:str,
21662171
type:str,
2167-
*args
2172+
*args:str
21682173
)->None:
21692174
ifnameinself.destinations:
21702175
fail("Destination already exists: "+repr(name))
2171-
self.destinations[name]=Destination(name,type,self,*args)
2176+
self.destinations[name]=Destination(name,type,self,args)
21722177

21732178
defget_destination(self,name:str)->Destination:
21742179
d=self.destinations.get(name)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp