Skip to content

gh-113317: AC converter: Use add_include() in bad_argument() - #114324

Closed
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:ac_add_include
Closed

gh-113317: AC converter: Use add_include() in bad_argument()#114324
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:ac_add_include

Conversation

@vstinner

@vstinnervstinner commented Jan 19, 2024

Copy link
Copy Markdown
Member

Rename also the 'clinic' global variable to 'global_clinic'.

@vstinner

Copy link
Copy Markdown
MemberAuthor

Ah, my simple CConverter.add_include() implementation reached its limits:

 File "/home/runner/work/cpython/cpython/./Tools/clinic/clinic.py", line 3266, in bad_argument
self.add_include('pycore_modsupport.h', '_PyArg_BadArgument()')
File "/home/runner/work/cpython/cpython/./Tools/clinic/clinic.py", line 3339, in add_include
raise ValueError("a converter only supports a single include")
ValueError: a converter only supports a single include

Comment threadTools/clinic/clinic.py Outdated
@erlend-aasland

Copy link
Copy Markdown
Contributor

Ah, my simple CConverter.add_include() implementation reached its limits:

 File "/home/runner/work/cpython/cpython/./Tools/clinic/clinic.py", line 3266, in bad_argument
self.add_include('pycore_modsupport.h', '_PyArg_BadArgument()')
File "/home/runner/work/cpython/cpython/./Tools/clinic/clinic.py", line 3339, in add_include
raise ValueError("a converter only supports a single include")
ValueError: a converter only supports a single include

Yeah, I suspected that :) Well, it should be straight forward to support multiple includes in converters; we could extract the nice "condition" logic you added for Clinic.add_include and reuse that for CConverter.add_include.

@erlend-aasland

Copy link
Copy Markdown
Contributor

Also, I think the clinic global renaming should be kept out; this PR is likely to grow a little bit.

* Rename the 'clinic' global variable to 'global_clinic'.
* Make CConverter.add_include() smarter. Don't fail when adding
exactly the same include twice.
* Copy converters includes later in output_templates().
@vstinner

vstinner commented Jan 19, 2024

Copy link
Copy Markdown
MemberAuthor

Sorry, I should have run tests locally, or mark this PR as a draft. I didn't expect so many back and forth.

All issues should now be fixed (let's see what the CI says).

# added late
for converter in converters:
include = converter.include
if include is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think that can be made an assert.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Not all converters need a special include. Do you mean that include variable is never None?

@vstinner

Copy link
Copy Markdown
MemberAuthor

commit e14930f was merged instead, I close my PR.

@vstinner
vstinner deleted the ac_add_include branch January 30, 2024 15:20
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@vstinner@erlend-aasland