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-103319: Fix `inspect.getsourcelines()` to return 1-based line numbers by artemmukhin · Pull Request #103226 · python/cpython

Conversation

@artemmukhin

@artemmukhin artemmukhin commented Apr 3, 2023 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

The problem is described in GH-103225.

I did not find any other usages of a line number returned by inspect.getsourcelines() except for pdb. However, I am not sure how many external usages of inspect.getsourcelines() already rely on 0-based line numbers for modules.

  • Issue: inspect.{getsourcelines, findsource} return 0 as the starting line number for modules #103319

Sorry, something went wrong.

Uh oh!

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

All reactions
@artemmukhin
pythonGH-103225: Fix inspect.getsourcelines() to return 1-based lin…
25585fc
…e numbers
@bedevere-bot bedevere-bot added the awaiting review label Apr 3, 2023
@bedevere-bot bedevere-bot mentioned this pull request Apr 3, 2023
pdb shows wrong line numbers for modules #103225
Closed
@ghost

ghost commented Apr 3, 2023 •
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.

@artemmukhin

artemmukhin commented Apr 3, 2023

Copy link
Copy Markdown
Contributor Author

@iritkatriel Could you please take a look, as this is a follow-up to #101674 you already reviewed?

Cc @gaogaotiantian

All reactions

Sorry, something went wrong.

Uh oh!

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

@blurb-it
📜🤖 Added by blurb_it.
d6e4012
@gaogaotiantian

gaogaotiantian commented Apr 3, 2023

Copy link
Copy Markdown
Member

1-based does seem more reasonable. But if we are fixing this, how about the code in inspect.findsource()? It's also 0-based.

All reactions

Sorry, something went wrong.

Uh oh!

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

@iritkatriel

iritkatriel commented Apr 3, 2023

Copy link
Copy Markdown
Member

@iritkatriel Could you please take a look, as this is a follow-up to #101674 you already reviewed?

Cc @gaogaotiantian

The bug in pdb that you describe in the issue may be new, but you are changing behaviour of inspect in the PR. Question is whether this is a bug in inspect.

All reactions

Sorry, something went wrong.

Uh oh!

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

@gaogaotiantian

gaogaotiantian commented Apr 3, 2023

Copy link
Copy Markdown
Member

The doc of inspect says this function Return a list of source lines and starting line number for an object. In my opinion, starting line number should not be 0. How is "starting from 0" and "starting from 1" different? They all include line 1 and there's no line 0. The fundamental of 0-based is that [0] means something and that's not the case in line number.

I would think this as a bug, but it's true that this is a breaking behavior. If we kept it as it is in inspect, I'd like to fix it in pdb.

All reactions

Sorry, something went wrong.

Uh oh!

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

@arhadthedev arhadthedev added the stdlib Standard Library Python modules in the Lib/ directory label Apr 4, 2023
@iritkatriel

iritkatriel commented Apr 4, 2023

Copy link
Copy Markdown
Member

If there's a fix in pdb that you can do so we don't release a new bug there, then let's do it. Changing inspect probably would require more discussion.

FYI @Yhg1s .

All reactions

Sorry, something went wrong.

Uh oh!

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

@artemmukhin

artemmukhin commented Apr 4, 2023

Copy link
Copy Markdown
Contributor Author

@iritkatriel Thank you for the quick response. That sounds reasonable. I can create a separate issue regarding inspect and then relink this PR, leaving #103225 unassigned for now. Is that OK?

@gaogaotiantian Thanks for pointing inspect.findsource() out. I will investigate it further and provide a summary in the new issue.

All reactions

Sorry, something went wrong.

Uh oh!

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

@gaogaotiantian gaogaotiantian mentioned this pull request Apr 6, 2023
gh-103225: Fixed zero lineno issue for pdb #103265
Merged
@artemmukhin

artemmukhin commented Apr 6, 2023

Copy link
Copy Markdown
Contributor Author

@iritkatriel @gaogaotiantian I have opened a new issue regarding inspect #103319

All reactions

Sorry, something went wrong.

Uh oh!

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

@artemmukhin artemmukhin changed the title GH-103225: Fix inspect.getsourcelines() to return 1-based line numbers GH-103319: Fix inspect.getsourcelines() to return 1-based line numbers Apr 6, 2023
@bedevere-bot bedevere-bot mentioned this pull request Apr 6, 2023
inspect.{getsourcelines, findsource} return 0 as the starting line number for modules #103319
Open
@George-Ogden

George-Ogden commented Jul 20, 2025

Copy link
Copy Markdown
Contributor

A solution may be to change the documentation, rather than the result, so that existing code does not break.

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions

github-actions Bot commented Apr 12, 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 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

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

Assignees

No one assigned

Labels

awaiting review stale Stale PR or inactive for long period of time. stdlib Standard Library Python modules in the Lib/ directory

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

@artemmukhin @gaogaotiantian @iritkatriel @George-Ogden @arhadthedev @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.