Skip to content

Commit

Permalink
pythongh-108494: AC: change parse_file() API
Browse files Browse the repository at this point in the history
Revert my change adding 'ns' parameter, add back 'verify' parameter,
and add also 'limited_capi' parameter.
  • Loading branch information
vstinner committed Aug 26, 2023
1 parent 713afb8 commit e9753e5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
10 changes: 1 addition & 9 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
from clinic import DSLParser


def default_namespace():
ns = types.SimpleNamespace()
ns.force = False
ns.limited_capi = clinic.DEFAULT_LIMITED_CAPI
return ns


def _make_clinic(*, filename='clinic_tests'):
clang = clinic.CLanguage(None)
c = clinic.Clinic(clang, filename=filename)
Expand Down Expand Up @@ -704,9 +697,8 @@ def expect_parsing_failure(
self, *, filename, expected_error, verify=True, output=None
):
errmsg = re.escape(dedent(expected_error).strip())
ns = default_namespace()
with self.assertRaisesRegex(clinic.ClinicError, errmsg):
clinic.parse_file(filename, ns=ns)
clinic.parse_file(filename)

def test_parse_file_no_extension(self) -> None:
self.expect_parsing_failure(
Expand Down
11 changes: 6 additions & 5 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2593,11 +2593,10 @@ def __repr__(self) -> str:
def parse_file(
filename: str,
*,
ns: argparse.Namespace,
output: str | None = None,
verify: bool = True,
limited_capi: bool = DEFAULT_LIMITED_CAPI,
) -> None:
verify = not ns.force
limited_capi = ns.limited_capi
if not output:
output = filename

Expand Down Expand Up @@ -6158,7 +6157,8 @@ def run_clinic(parser: argparse.ArgumentParser, ns: argparse.Namespace) -> None:
continue
if ns.verbose:
print(path)
parse_file(path, ns=ns)
parse_file(path,
verify=not ns.force, limited_capi=ns.limited_capi)
return

if not ns.filename:
Expand All @@ -6170,7 +6170,8 @@ def run_clinic(parser: argparse.ArgumentParser, ns: argparse.Namespace) -> None:
for filename in ns.filename:
if ns.verbose:
print(filename)
parse_file(filename, output=ns.output, ns=ns)
parse_file(filename, output=ns.output,
verify=not ns.force, limited_capi=ns.limited_capi)


def main(argv: list[str] | None = None) -> NoReturn:
Expand Down

0 comments on commit e9753e5

Please sign in to comment.