GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-108494: AC: change parse_file() API by vstinner · Pull Request #108504 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Aug 26, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Revert my change adding 'ns' parameter, add back 'verify' parameter, and add also 'limited_capi' parameter.

  • Issue: Add support for the limited C API to Argument Clinic #108494

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@vstinner vstinner added the skip news label Aug 26, 2023
@vstinner
vstinner requested review from AlexWaygood and erlend-aasland as code owners August 26, 2023 00:34
@bedevere-bot bedevere-bot mentioned this pull request Aug 26, 2023
Add support for the limited C API to Argument Clinic #108494
Closed
@bedevere-bot bedevere-bot added the awaiting core review label Aug 26, 2023
@vstinner vstinner mentioned this pull request Aug 26, 2023
gh-108494: Argument Clinic partial supports of Limited C API #108495
Merged
@vstinner
vstinner force-pushed the ac_args branch from 46f74b4 to e9753e5 Compare August 26, 2023 00:35
serhiy-storchaka
serhiy-storchaka reviewed Aug 26, 2023
View reviewed changes
Comment thread Tools/clinic/clinic.py
ns: argparse.Namespace,
output: str | None = None,
verify: bool = True,
limited_capi: bool = DEFAULT_LIMITED_CAPI,

@serhiy-storchaka serhiy-storchaka Aug 26, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if it specify the version of the limited API, not a simple boolean.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@vstinner vstinner Aug 26, 2023

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, it only supports Python 3.13. The value can be changed to an int later

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
serhiy-storchaka
serhiy-storchaka approved these changes Aug 27, 2023
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Aug 27, 2023
@vstinner

vstinner commented Aug 27, 2023

Copy link
Copy Markdown
Member Author

I'm waiting for the review @AlexWaygood, he proposed that change.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood

AlexWaygood commented Aug 27, 2023

Copy link
Copy Markdown
Member

Thanks for fixing this up!

I had a work event all day yesterday and I'm visiting family today; I'd like to take a proper look tomorrow

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland
erlend-aasland approved these changes Aug 28, 2023
View reviewed changes
AlexWaygood
AlexWaygood reviewed Aug 28, 2023
View reviewed changes
Comment thread Tools/clinic/clinic.py
Comment on lines +2597 to +2617
verify: bool = True,
limited_capi: bool = DEFAULT_LIMITED_CAPI,

@AlexWaygood AlexWaygood Aug 28, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are using a global DEFAULT_LIMITED_CAPI constant for the default value here, then I think we should also use it for the default value in Clinic.__init__, instead of hardcoding it to False there:

cpython/Tools/clinic/clinic.py

Line 2393 in 0e8b3fc

limited_capi: bool = False,

Though, I'm actually not sure either verify or limited_capi need to have default values. There aren't any places in clinic.py where parse_file is currently called without explicitly passing values to these parameters. And in general, I prefer to avoid having default values unless there's a good reason to have a default value. It forces you to be explicit about the values that are being passed to the function at every callsite, which reduces the potential for accidental bugs to creep in.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@vstinner vstinner Aug 28, 2023

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a variable for the default to consider changing it tomorrow if AC is shipped as a third party tool.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@AlexWaygood AlexWaygood Aug 28, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be making decisions now on the basis that we might want to ship AC as a third-party tool in the future. Making AC suitable for use in third-party projects would require quite a few changes across Tools/clinic/. It's not currently a goal to make it suitable for use in third-party projects, and I'd like us to have a proper discussion about the pros and cons for doing so before we change that policy. It's pretty clearly documented at the moment that it's only intended as an internal tool: see the note: paragraph at the top of https://docs.python.org/3/howto/clinic.html#argument-clinic-how-to.

But even if we did want to flip the default tomorrow, I don't think the current structure would make it easy to do so. We'd have to change three places in the code:

diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 96ae1e5ad6..5ddaeea855 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -63,7 +63,7 @@

 version = '1'

-DEFAULT_LIMITED_CAPI = False
+DEFAULT_LIMITED_CAPI = True
 NO_VARARG = "PY_SSIZE_T_MAX"
 CLINIC_PREFIX = "__clinic_"
 CLINIC_PREFIXED_ARGS = {
@@ -2390,7 +2390,7 @@ def __init__(
             *,
             filename: str,
             verify: bool = True,
-            limited_capi: bool = False,
+            limited_capi: bool = True,
     ) -> None:
         # maps strings to Parser objects.
         # (instantiated from the "parsers" global.)
@@ -6065,7 +6065,7 @@ def create_cli() -> argparse.ArgumentParser:
     cmdline.add_argument("--exclude", type=str, action="append",
                          help=("a file to exclude in --make mode; "
                                "can be given multiple times"))
-    cmdline.add_argument("--limited", dest="limited_capi", action='store_true',
+    cmdline.add_argument("--no-limited", dest="limited_capi", action='store_false',
                          help="use the Limited C API")
     cmdline.add_argument("filename", metavar="FILE", type=str, nargs="*",
                          help="the list of files to process")

But if we make it so that neither parse_file nor Clinic.__init__ have a default value for the limited_capi parameter, then there will be a "single source of truth" in AC for whether the limited C API is the default or not, and we would only have to make this change when/if we decide to flip the default:

diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 96ae1e5ad6..8866a52f71 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -6065,7 +6065,7 @@ def create_cli() -> argparse.ArgumentParser:
     cmdline.add_argument("--exclude", type=str, action="append",
                          help=("a file to exclude in --make mode; "
                                "can be given multiple times"))
-    cmdline.add_argument("--limited", dest="limited_capi", action='store_true',
+    cmdline.add_argument("--no-limited", dest="limited_capi", action='store_false',
                          help="use the Limited C API")
     cmdline.add_argument("filename", metavar="FILE", type=str, nargs="*",
                          help="the list of files to process")

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@vstinner vstinner Aug 28, 2023

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are using a global DEFAULT_LIMITED_CAPI constant for the default value here, then I think we should also use it for the default value in Clinic.init, instead of hardcoding it to False there: (...)

Done.

If you prefer, I can just remove DEFAULT_LIMITED_CAPI. Changing the default tomorrow is not a big deal.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
vstinner added 2 commits August 28, 2023 18:16
@vstinner
pythongh-108494: AC: change parse_file() API
0b1ae97
Revert my change adding 'ns' parameter, add back 'verify' parameter,
and add also 'limited_capi' parameter.
@vstinner
Clinic constructor uses DEFAULT_LIMITED_CAPI
e9f70f2
@vstinner
vstinner force-pushed the ac_args branch from e9753e5 to e9f70f2 Compare August 28, 2023 16:17
@vstinner

vstinner commented Aug 28, 2023

Copy link
Copy Markdown
Member Author

@AlexWaygood: Would you mind to review the updated PR? Do you prefer to keep DEFAULT_LIMITED_CAPI, or remove it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood

AlexWaygood commented Aug 28, 2023

Copy link
Copy Markdown
Member

I still have a bunch of nits: I don't think we need the MockClinic class that was added to the test file in 1dd9510; the types import in the test file is now an unused import; and I still think it would be better to make limited_capi a required argument everywhere. I made #108575 as an alternative PR, which builds on this one :)

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood AlexWaygood mentioned this pull request Aug 28, 2023
gh-108494: Argument clinic: Improve the parse_file() API #108575
Merged
@AlexWaygood AlexWaygood closed this in #108575 Aug 28, 2023
@vstinner
vstinner deleted the ac_args branch August 28, 2023 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@AlexWaygood AlexWaygood AlexWaygood left review comments
@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes
@erlend-aasland erlend-aasland erlend-aasland approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting merge skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@vstinner @AlexWaygood @serhiy-storchaka @erlend-aasland @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.