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-123339: Fix cases of inconsistency of __module__ and __firstlineno__ in classes by serhiy-storchaka · Pull Request #123613 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Sep 2, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member
  • Setting the __module__ attribute for a class now removes the __firstlineno__ item from the type's dict.
  • The _collections_abc and _pydecimal modules now completely replace the collections.abc and decimal modules after importing the latter. This allows to get the source of classes and functions defined in these modules.
  • inspect.findsource() now checks whether the first line number for a class is out of bound.
  • Issue: Python's help utility crashes when collections.abc module is asked. #123339

Sorry, something went wrong.

Uh oh!

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

All reactions
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.13 only security fixes label Sep 2, 2024
@bedevere-app bedevere-app Bot added the awaiting core review label Sep 2, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Sep 2, 2024
Python's help utility crashes when collections.abc module is asked. #123339
Closed
@bedevere-app bedevere-app Bot added the docs Documentation in the Doc dir label Sep 2, 2024
@serhiy-storchaka
serhiy-storchaka requested review from a team and rhettinger September 2, 2024 18:09
@Eclips4 Eclips4 changed the title __ in classesgh-123339: Fix cases of inconsistency of __module__ and __firstlineno__ in classes gh-123339: Fix cases of inconsistency of __module__ and __firstlineno__ in classes Sep 2, 2024
@Eclips4

Eclips4 commented Sep 2, 2024

Copy link
Copy Markdown
Member

Serhiy, it's seems that you forgot to commit the actual fix(and tests) and accidentally added two NEWS entries

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka
pythongh-123339: Fix cases of inconsistency of __module__ and __first…
f2a8b90
…lineno__ in classes

* Setting the __module__ attribute for a class now removes the
  __firstlineno__ item from the type's dict.
* The _collections_abc and _pydecimal modules now completely replace the
  collections.abc and decimal modules after importing the latters. This
  allows to get the source of classes and functions defined in these
  modules.
* inspect.findsource() now checks whether the first line number for a
  class is out of bound.
@serhiy-storchaka
serhiy-storchaka force-pushed the firstlineno-with-changed-module branch from fa4c94a to f2a8b90 Compare September 2, 2024 18:26
@serhiy-storchaka
serhiy-storchaka requested a review from markshannon as a code owner September 2, 2024 18:26
@serhiy-storchaka

serhiy-storchaka commented Sep 2, 2024

Copy link
Copy Markdown
Member Author

Thanks for noticing this @Eclips4! I somewhere accidentally used --amend.

Two NEWS entries are intentional, as they belong to different sections (Core and Library).

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

picnixz
picnixz reviewed Sep 3, 2024
View reviewed changes
Comment thread Lib/inspect.py Resolved

Uh oh!

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

Comment thread Doc/reference/datamodel.rst Outdated

:attr:`__firstlineno__`
The line number of the first line of the class definition, including decorators.
Setting :attr:`__module__` removes :attr:`__firstlineno__`.

@picnixz picnixz Sep 3, 2024

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.

Suggested change
Setting :attr:`__module__` removes :attr:`__firstlineno__`.
Setting :attr:`!__module__` removes :attr:`!__firstlineno__`.

Note that the link to __module__ does not exist (we don't have a global .. attribute:: __module__). We can address this issue in a follow-up PR, but for now, let's just suppress the link.

Sorry, something went wrong.

Uh oh!

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

serhiy-storchaka reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@serhiy-storchaka serhiy-storchaka Sep 3, 2024

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

Well, the link to __firstlineno__ should be suppressed, but the link to __module__ may work in future.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Lib/collections/abc.py Resolved

Uh oh!

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

@picnixz picnixz mentioned this pull request Sep 3, 2024
gh-123339: fix out-of-bounds values in inspect.findsource #123347
Closed
serhiy-storchaka
serhiy-storchaka commented Sep 3, 2024
View reviewed changes
Comment thread Lib/inspect.py Resolved

Uh oh!

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

Comment thread Doc/reference/datamodel.rst Outdated

:attr:`__firstlineno__`
The line number of the first line of the class definition, including decorators.
Setting :attr:`__module__` removes :attr:`__firstlineno__`.

@serhiy-storchaka serhiy-storchaka Sep 3, 2024

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

Well, the link to __firstlineno__ should be suppressed, but the link to __module__ may work in future.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/reference/datamodel.rst Resolved

Uh oh!

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

@serhiy-storchaka
Update Doc/reference/datamodel.rst
26f4c38
@rhettinger
rhettinger removed their request for review September 3, 2024 10:24
jaraco
jaraco approved these changes Sep 27, 2024
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Sep 27, 2024
@serhiy-storchaka
Merge branch 'main' into firstlineno-with-changed-module
85178e7
@serhiy-storchaka
serhiy-storchaka requested review from rhettinger and willingc as code owners September 28, 2024 11:42
@serhiy-storchaka
serhiy-storchaka merged commit 69a4063 into python:main Sep 28, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Sep 28, 2024
@miss-islington-app

miss-islington-app Bot commented Sep 28, 2024

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka
serhiy-storchaka deleted the firstlineno-with-changed-module branch September 28, 2024 17:51
@miss-islington-app

miss-islington-app Bot commented Sep 28, 2024

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 69a4063ca516360b5eb96f5432ad9f9dfc32a72e 3.13
All reactions

Sorry, something went wrong.

Uh oh!

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

@miss-islington-app miss-islington-app Bot assigned serhiy-storchaka Sep 28, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Sep 28, 2024
@serhiy-storchaka
[3.13] pythongh-123339: Fix cases of inconsistency of __module__ and …
27a195e
…__firstlineno__ in classes (pythonGH-123613)

* Setting the __module__ attribute for a class now removes the
  __firstlineno__ item from the type's dict.
* The _collections_abc and _pydecimal modules now completely replace the
  collections.abc and decimal modules after importing them. This
  allows to get the source of classes and functions defined in these
  modules.
* inspect.findsource() now checks whether the first line number for a
  class is out of bound.
(cherry picked from commit 69a4063)

Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-app

bedevere-app Bot commented Sep 28, 2024

Copy link
Copy Markdown

GH-124735 is a backport of this pull request to the 3.13 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Sep 28, 2024
@serhiy-storchaka serhiy-storchaka removed their assignment Sep 28, 2024
Yhg1s pushed a commit that referenced this pull request Sep 30, 2024
@serhiy-storchaka
[3.13] gh-123339: Fix cases of inconsistency of __module__ and __firs…
5bf32d1
…tlineno__ in classes (GH-123613) (#124735)

* Setting the __module__ attribute for a class now removes the
  __firstlineno__ item from the type's dict.
* The _collections_abc and _pydecimal modules now completely replace the
  collections.abc and decimal modules after importing them. This
  allows to get the source of classes and functions defined in these
  modules.
* inspect.findsource() now checks whether the first line number for a
  class is out of bound.
(cherry picked from commit 69a4063)
@colesbury colesbury mentioned this pull request Oct 11, 2024
Race condition when importing collections.abc #125245
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@picnixz picnixz picnixz left review comments
@jaraco jaraco jaraco approved these changes
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
@willingc willingc Awaiting requested review from willingc willingc is a code owner
@rhettinger rhettinger Awaiting requested review from rhettinger rhettinger is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

docs Documentation in the Doc dir

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.

4 participants

@serhiy-storchaka @Eclips4 @jaraco @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.