diff options
author | Larry Hastings <larry@hastings.org> | 2014-01-07 20:21:08 (GMT) |
---|---|---|
committer | Larry Hastings <larry@hastings.org> | 2014-01-07 20:21:08 (GMT) |
commit | 9026113fd4acbb2fb77a900ae7bd921eebcc29c4 (patch) | |
tree | cc529474ed8aeed9d1e89f23b131be7e8ea94d16 /Tools/clinic/clinic.py | |
parent | 77561cccb277f5347fc1c41a2fb06b7cc3194b8a (diff) | |
download | cpython-9026113fd4acbb2fb77a900ae7bd921eebcc29c4.zip cpython-9026113fd4acbb2fb77a900ae7bd921eebcc29c4.tar.gz cpython-9026113fd4acbb2fb77a900ae7bd921eebcc29c4.tar.bz2 |
Issue #20157: When Argument Clinic renames a parameter because its name
collides with a C keyword, it no longer exposes that rename to PyArg_Parse.
Diffstat (limited to 'Tools/clinic/clinic.py')
-rwxr-xr-x | Tools/clinic/clinic.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 78600ee..5378a0b 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -8,7 +8,6 @@ import abc import ast import atexit -import clinic import collections import contextlib import functools @@ -898,13 +897,21 @@ class BlockParser: def parse_clinic_block(self, dsl_name): input_add, input_output = text_accumulator() self.block_start_line_number = self.line_number + 1 - stop_line = self.language.stop_line.format(dsl_name=dsl_name) + '\n' + stop_line = self.language.stop_line.format(dsl_name=dsl_name) body_prefix = self.language.body_prefix.format(dsl_name=dsl_name) + def is_stop_line(line): + # make sure to recognize stop line even if it + # doesn't end with EOL (it could be the very end of the file) + if not line.startswith(stop_line): + return False + remainder = line[len(stop_line):] + return (not remainder) or remainder.isspace() + # consume body of program while self.input: line = self._line() - if line == stop_line or self.is_start_line(line): + if is_stop_line(line) or self.is_start_line(line): break if body_prefix: line = line.lstrip() @@ -1396,7 +1403,8 @@ class CConverter(metaclass=CConverterAutoRegister): data is a CRenderData instance. """ self.parameter = parameter - name = ensure_legal_c_identifier(self.name) + original_name = self.name + name = ensure_legal_c_identifier(original_name) # declarations d = self.declaration() @@ -1414,7 +1422,7 @@ class CConverter(metaclass=CConverterAutoRegister): data.impl_arguments.append(self.length_name()) # keywords - data.keywords.append(name) + data.keywords.append(original_name) # format_units if self.is_optional() and '|' not in data.format_units: |