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-87465: Make pyclbr.readmodule_ex() not die on module w/o __spec__ by kxrob · Pull Request #24623 · python/cpython

Conversation

@kxrob

@kxrob kxrob commented Feb 22, 2021 •
edited by serhiy-storchaka
Loading

Uh oh!

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

Copy link
Copy Markdown

pyclbr.readmodule_ex() should not die when traversing
an "import main" statement or an import of another
module without spec attribute.

https://bugs.python.org/issue43299

https://bugs.python.org/issue43299

  • Issue: pyclbr.readmodule_ex traversing "import __main__": dies with ValueError: __main__.__spec__ is None / is not set #87465

Sorry, something went wrong.

Uh oh!

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

All reactions
@kxrob
bpo-43299: Make pyclbr.readmodule_ex() not die on module w/o __spec__
f1fd91e
pyclbr.readmodule_ex() should not die when traversing
an "import __main__" statement or an import of another
module without __spec__ attribute.
@the-knights-who-say-ni

the-knights-who-say-ni commented Feb 22, 2021

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@kxrob

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

All reactions

Sorry, something went wrong.

Uh oh!

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

@the-knights-who-say-ni the-knights-who-say-ni added the CLA not signed label Feb 22, 2021
@bedevere-bot bedevere-bot added the awaiting review label Feb 22, 2021
@the-knights-who-say-ni the-knights-who-say-ni added CLA signed and removed CLA not signed labels Mar 4, 2021
@github-actions

github-actions Bot commented Apr 4, 2021

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 4, 2021
@kxrob

kxrob commented Apr 4, 2021

Copy link
Copy Markdown
Author

Is there a chance this bug can be solved? @vstinner

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Apr 5, 2021
akulakov
akulakov reviewed Jul 6, 2021
View reviewed changes
Comment thread Lib/pyclbr.py
try: spec = importlib.util._find_spec_from_path(fullmodule, search_path)
except ValueError:
# ValueError: __main__.__spec__ is None / is not set
spec = None

@akulakov akulakov Jul 6, 2021

Copy link
Copy Markdown
Contributor

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.

It looks like this would just lead to ModuleNotFoundError below, which seems misleading because module does exist. Is ModuleNotFoundError caught somewhere and pyclbr proceeds to next module? Did you test if this change fixes the reported bug?

Sorry, something went wrong.

Uh oh!

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

All reactions

@kxrob kxrob Jul 6, 2021

Copy link
Copy Markdown
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.

The change from ValueError to an ImportError (subclass) makes it to be processed reasonable (skip to next) in the caller https://github.com/python/cpython/blob/3.10/Lib/pyclbr.py#L243 / visit_Import() in the call stack shown by the trace in bpo 43299 (2 levels higher). And solves the bug in that case at least - and similar in other callers of _readmodule()
In that case the module (main) can indeed not be found in the filesystem for parsing. regular modules have a spec. Raising an ImportError with extra specific text could be another option.

Sorry, something went wrong.

Uh oh!

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

akulakov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@kxrob kxrob mannequin mentioned this pull request May 22, 2022
pyclbr.readmodule_ex traversing "import __main__": dies with ValueError: __main__.__spec__ is None / is not set #87465
Open
@ezio-melotti ezio-melotti removed the CLA signed label Jul 13, 2022
@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 9, 2026
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Aug 11, 2026
@serhiy-storchaka serhiy-storchaka changed the title bpo-43299: Make pyclbr.readmodule_ex() not die on module w/o __spec__ gh-87465: Make pyclbr.readmodule_ex() not die on module w/o __spec__ Aug 12, 2026
@ambv

ambv commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

This PR has not been touched by a human in more than 5 years. Closing to cull the number of open pull requests. Do not reopen this pull request without getting a go-ahead from a triager or core developer on the related issue.

All reactions

Sorry, something went wrong.

Uh oh!

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

@ambv ambv closed this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@akulakov akulakov akulakov left review comments

Uh oh!

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

Assignees

No one assigned

Labels

awaiting review

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.

6 participants

@kxrob @the-knights-who-say-ni @ambv @akulakov @ezio-melotti @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.