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-94808: Remove unused code in _make_posargs by mjdominus · Pull Request #119227 · python/cpython

Conversation

@mjdominus

@mjdominus mjdominus commented May 20, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

The coverage report indicates that this branch is never exercised. That appears to be because it is unused code. When I couldn't produce a test case that exercised it, I removed the branch, then checked that the complete test suite still passed.

The branch is only run when names_with_default is null. It appears that when there are no names with defaults, names_with_defaults will point to a structure that has .size zero.

It's possible that a future implementation change might alter that, requiring the branch to be put back, but I believe the existing tests would detect if that happened.

  • Issue: Metabug: Improving C-level coverage #94808

Sorry, something went wrong.

Uh oh!

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

All reactions
@mjdominus
mjdominus requested review from lysnikolaou and pablogsal as code owners May 20, 2024 16:06
@bedevere-app

bedevere-app Bot commented May 20, 2024

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot added the awaiting review label May 20, 2024
@bedevere-app bedevere-app Bot mentioned this pull request May 20, 2024
Metabug: Improving C-level coverage #94808
Open
@mjdominus

mjdominus commented May 20, 2024

Copy link
Copy Markdown
Contributor Author

@encukou

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou

encukou commented May 21, 2024

Copy link
Copy Markdown
Member

The current code covers all combinations of plain_names & names_with_default being NULL and non-NULL. Removing one of the cases breaks that, leaving no hint about why this would fall through to the empty posargs case.
If it was me, I'd replace the branch with something like:

// With the current grammar, we never get here.
// When that changes, remove the assert, and test thoroughly.
assert(0);
*posargs = plain_names;
lysnikolaou and mjdominus reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

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

@mjdominus

mjdominus commented May 22, 2024

Copy link
Copy Markdown
Contributor Author

I'd replace the branch with something like:

I agree, that's better. Should I resubmit?

All reactions

Sorry, something went wrong.

Uh oh!

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

@mjdominus
mjdominus force-pushed the mjd2 branch 2 times, most recently from 4b8f4ac to 4a15e0a Compare May 22, 2024 06:50
@ghost

ghost commented May 22, 2024 •
edited by ghost
Loading

Uh oh!

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

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

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

@mjdominus
mjdominus marked this pull request as draft May 22, 2024 07:32
@bedevere-app bedevere-app Bot removed the awaiting review label May 22, 2024
@encukou

encukou commented May 22, 2024

Copy link
Copy Markdown
Member

This looks good to me, thanks!
I see you've marked it as draft, do you still want to make changes?

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou encukou added the skip news label May 22, 2024
@mjdominus

mjdominus commented May 28, 2024

Copy link
Copy Markdown
Contributor Author

Thanks! I meant to wrap this up over the weekend, but forgot. I will do it this week.

All reactions

Sorry, something went wrong.

Uh oh!

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

@mjdominus
mjdominus force-pushed the mjd2 branch from 013bbf9 to 6dcfe64 Compare June 4, 2024 01:58
mjdominus added 2 commits June 3, 2024 22:01
@mjdominus
Remove unused branch in _make_posargs
ead1013
`names_with_default` is never `NULL`, even if there are no names with
defaults.  In that case it points to a structure with `size` zero.

Rather than eliminating the branch, we leave it behind with an `assert(0)`
in case a future change to the grammar exercises the branch.
@mjdominus
Reorganize four-way if-elsif-elsif-elsif as nested if-elses
3cf3f84
@mjdominus
mjdominus force-pushed the mjd2 branch from 6dcfe64 to 3cf3f84 Compare June 4, 2024 02:05
@mjdominus
mjdominus marked this pull request as ready for review June 4, 2024 02:06
@bedevere-app bedevere-app Bot added the awaiting review label Jun 4, 2024
@mjdominus

mjdominus commented Jun 4, 2024

Copy link
Copy Markdown
Contributor Author

@encukou I split the changes into two commits, one to improve coverage and the other to reorganize the if-else structure.

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou

encukou commented Jun 4, 2024

Copy link
Copy Markdown
Member

Thanks!

For the future: please avoid force-pushing to CPython -- when reviewed commits disappear, the review needs to be restarted. (In this commit it's not a problem, as it's just a few lines.)
Reorganizing the commits doesn't help, since all PRs are squashed when merging.

mjdominus 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.

@encukou
encukou merged commit bd8c1f9 into python:main Jun 4, 2024
@bedevere-app bedevere-app Bot removed the awaiting review label Jun 4, 2024
@mjdominus
mjdominus deleted the mjd2 branch June 4, 2024 13:56
@mjdominus

mjdominus commented Jun 4, 2024

Copy link
Copy Markdown
Contributor Author

Thanks again for your help and guidance through the whole process.

All reactions

Sorry, something went wrong.

Uh oh!

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

barneygale pushed a commit to barneygale/cpython that referenced this pull request Jun 5, 2024
@mjdominus @barneygale
pythongh-94808: Reorganize _make_posargs and mark unused code (python…
d811474
…GH-119227)

* Reorganize four-way if-elsif-elsif-elsif as nested if-elses
* Mark unused branch in _make_posargs

`names_with_default` is never `NULL`, even if there are no names with
defaults.  In that case it points to a structure with `size` zero.

Rather than eliminating the branch, we leave it behind with an `assert(0)`
in case a future change to the grammar exercises the branch.
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
@mjdominus @estyxx
pythongh-94808: Reorganize _make_posargs and mark unused code (python…
0448bdc
…GH-119227)

* Reorganize four-way if-elsif-elsif-elsif as nested if-elses
* Mark unused branch in _make_posargs

`names_with_default` is never `NULL`, even if there are no names with
defaults.  In that case it points to a structure with `size` zero.

Rather than eliminating the branch, we leave it behind with an `assert(0)`
in case a future change to the grammar exercises the branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pablogsal pablogsal Awaiting requested review from pablogsal pablogsal is a code owner
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

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.

2 participants

@mjdominus @encukou
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.