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-143552: Fix inspect.getcoroutinestate for generator-based coroutines by VanshAgarwal24036 · Pull Request #143609 · python/cpython

Conversation

@VanshAgarwal24036

@VanshAgarwal24036 VanshAgarwal24036 commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

Generator-based coroutines created via types.coroutine() are plain generators
and do not expose the coroutine introspection attributes expected by
inspect.getcoroutinestate(), causing AttributeError.

This change adds minimal read-only aliases on generators for the required
cr_* attributes, delegating to existing gi_* state, restoring compatibility
without altering semantics.

Fixes gh-143552.

Sorry, something went wrong.

Uh oh!

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

All reactions
@VanshAgarwal24036
Fix inspect.getcoroutinestate for generator-based coroutines
43b157b
@VanshAgarwal24036
VanshAgarwal24036 requested a review from markshannon as a code owner January 9, 2026 14:20
@bedevere-app bedevere-app Bot added the awaiting review label Jan 9, 2026
@VanshAgarwal24036 VanshAgarwal24036 changed the title Fix inspect.getcoroutinestate for generator-based coroutines gh-143552: Fix inspect.getcoroutinestate for generator-based coroutines Jan 9, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Jan 9, 2026
types._GeneratorWrapper is no longer consistent with types.GeneratorType/types.CoroutineType #143552
Open
VanshAgarwal24036 added 2 commits January 9, 2026 19:59
@VanshAgarwal24036
Fix trailing whitespace in test_inspect
cc6a3b2
@VanshAgarwal24036
Fix pointer casts in generator coroutine getters
303ef4c
@VanshAgarwal24036

VanshAgarwal24036 commented Jan 9, 2026

Copy link
Copy Markdown
Contributor Author

This change is internal and does not require a NEWS entry.
Could a core dev please add the skip news label?

All reactions

Sorry, something went wrong.

Uh oh!

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

@ZeroIntensity

ZeroIntensity commented Jan 9, 2026

Copy link
Copy Markdown
Member

This change is internal and does not require a NEWS entry.

No it's not, this is a user-facing bug.

All reactions

Sorry, something went wrong.

Uh oh!

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

ZeroIntensity
ZeroIntensity requested changes Jan 9, 2026
View reviewed changes

@ZeroIntensity ZeroIntensity left a comment

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.

Please, please, please ensure that you understand the issue and think about what you're doing before you submit an AI-generated PR. This change is the wrong approach and was not one of the suggested solutions in the issue.

If you're interested in contributing, I really encourage you to take the time to read through our devguide.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Lib/test/test_inspect/test_inspect.py
{'a': None, 'gencoro': gencoro, 'b': 'spam'})



@ZeroIntensity ZeroIntensity Jan 9, 2026

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.

Unrelated change.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Lib/test/test_inspect/test_inspect.py
Comment on lines +2890 to +2891
# Must not raise AttributeError
getcoroutinestate(gen_coro())

@ZeroIntensity ZeroIntensity Jan 9, 2026

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.

Add an assertion for what the proper state should be.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Objects/genobject.c
Comment on lines +979 to +983
{"cr_running", gen_get_cr_running, NULL, NULL},
{"cr_frame", gen_get_cr_frame, NULL, NULL},
{"cr_code", gen_get_cr_code, NULL, NULL},
{"cr_suspended", gen_get_cr_suspended, NULL, NULL},
{"cr_origin", gen_get_cr_origin, NULL, NULL},

@ZeroIntensity ZeroIntensity Jan 9, 2026

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.

This is wrong. Coroutine objects are not generator objects; they should not expose the coroutine interface solely for use in _GeneratorWrapper. _GeneratorWrapper should instead replicate these attributes.

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot removed the awaiting review label Jan 9, 2026
@bedevere-app

bedevere-app Bot commented Jan 9, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

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 changes label Jan 9, 2026
@VanshAgarwal24036

VanshAgarwal24036 commented Jan 9, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the detailed feedback — I understand now that my approach was incorrect.

I see that adding coroutine attributes to generator objects changes generator semantics and that the correct place to address this is _GeneratorWrapper, as discussed in the issue. I also understand that some of the changes (including test adjustments and formatting) were unrelated and added noise — that’s on me.

I’m still new to CPython contributions and I’ve been relying on tooling while learning, but I clearly should have slowed down and aligned more closely with the issue discussion and suggested solutions before opening the PR.

To avoid further confusion, I think the best next step is for me to close this PR, re-read the issue and devguide carefully, and only revisit this once I have a solution that matches the intended design. If you have any guidance on what would be a good next step for a new contributor here, I’d really appreciate it.

Apologies for the noise, and thank you for taking the time to review.

All reactions

Sorry, something went wrong.

Uh oh!

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

@picnixz picnixz closed this Jan 9, 2026
@picnixz

picnixz commented Jan 9, 2026

Copy link
Copy Markdown
Member

The best thing is:

  • Don't open PRs if the issue has not been discussed by core developers or triagers.
  • Don't use LLM to generate a PR. You can use it for understanding the code or writing English but not for writing PR.

If you have any guidance on what would be a good next step for a new contributor here, I’d really appreciate it.

The first thing to do is read the devguide. In general, "easy"-labelled issues are also good first contributions, unless there is already an open PR.

All reactions

Sorry, something went wrong.

Uh oh!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ZeroIntensity ZeroIntensity ZeroIntensity requested changes
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

awaiting changes

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

types._GeneratorWrapper is no longer consistent with types.GeneratorType/types.CoroutineType

Uh oh!

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

3 participants

@VanshAgarwal24036 @ZeroIntensity @picnixz
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.