@@ -116,11 +116,6 @@ def warn_or_fail(
116
116
line_number : int | None = None ,
117
117
) -> None :
118
118
joined = " " .join ([str (a ) for a in args ])
119
- if clinic :
120
- if filename is None :
121
- filename = clinic .filename
122
- if getattr (clinic , 'block_parser' , None ) and (line_number is None ):
123
- line_number = clinic .block_parser .line_number
124
119
error = ClinicError (joined , filename = filename , lineno = line_number )
125
120
if fail :
126
121
raise error
@@ -277,7 +272,7 @@ class Language(metaclass=abc.ABCMeta):
277
272
checksum_line = ""
278
273
279
274
def __init__ (self , filename : str ) -> None :
280
- ...
275
+ self . filename = filename
281
276
282
277
@abc .abstractmethod
283
278
def render (
@@ -833,8 +828,6 @@ def output_templates(
833
828
if not p .is_optional ():
834
829
min_kw_only = i - max_pos
835
830
elif p .is_vararg ():
836
- if vararg != self .NO_VARARG :
837
- fail ("Too many var args" )
838
831
pseudo_args += 1
839
832
vararg = i - 1
840
833
else :
@@ -1889,7 +1882,12 @@ def __next__(self) -> Block:
1889
1882
raise StopIteration
1890
1883
1891
1884
if self .dsl_name :
1892
- return_value = self .parse_clinic_block (self .dsl_name )
1885
+ try :
1886
+ return_value = self .parse_clinic_block (self .dsl_name )
1887
+ except ClinicError as exc :
1888
+ exc .filename = self .language .filename
1889
+ exc .lineno = self .line_number
1890
+ raise
1893
1891
self .dsl_name = None
1894
1892
self .first_block = False
1895
1893
return return_value
@@ -5071,14 +5069,16 @@ def parse(self, block: Block) -> None:
5071
5069
self .state (line )
5072
5070
except ClinicError as exc :
5073
5071
exc .lineno = line_number
5072
+ exc .filename = self .clinic .filename
5074
5073
raise
5075
5074
5076
5075
self .do_post_block_processing_cleanup (line_number )
5077
5076
block .output .extend (self .clinic .language .render (self .clinic , block .signatures ))
5078
5077
5079
5078
if self .preserve_output :
5080
5079
if block .output :
5081
- fail ("'preserve' only works for blocks that don't produce any output!" )
5080
+ fail ("'preserve' only works for blocks that don't produce any output!" ,
5081
+ line_number = line_number )
5082
5082
block .output = self .saved_output
5083
5083
5084
5084
def in_docstring (self ) -> bool :
@@ -5503,6 +5503,8 @@ def parse_parameter(self, line: str) -> None:
5503
5503
f"invalid parameter declaration (**kwargs?): { line !r} " )
5504
5504
5505
5505
if function_args .vararg :
5506
+ if any (p .is_vararg () for p in self .function .parameters .values ()):
5507
+ fail ("Too many var args" )
5506
5508
is_vararg = True
5507
5509
parameter = function_args .vararg
5508
5510
else :
@@ -6174,7 +6176,12 @@ def do_post_block_processing_cleanup(self, lineno: int) -> None:
6174
6176
return
6175
6177
6176
6178
self .check_remaining_star (lineno )
6177
- self .function .docstring = self .format_docstring ()
6179
+ try :
6180
+ self .function .docstring = self .format_docstring ()
6181
+ except ClinicError as exc :
6182
+ exc .lineno = lineno
6183
+ exc .filename = self .clinic .filename
6184
+ raise
6178
6185
6179
6186
6180
6187
0 commit comments