Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-128772: Fix - warnings.deprecated doesn't work well with pydoc #128781

Closed
wants to merge 25 commits into from

Conversation

srinivasreddy
Copy link
Contributor

@srinivasreddy srinivasreddy commented Jan 13, 2025

@srinivasreddy srinivasreddy marked this pull request as ready for review January 15, 2025 14:04
@srinivasreddy srinivasreddy marked this pull request as draft January 15, 2025 14:07
@srinivasreddy srinivasreddy marked this pull request as ready for review January 16, 2025 09:38
Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new test for the change to the warnings module belongs in test.test_warnings.

Revert this change to the idlelib file. This idle test is strictly for testing that idle reverts its monkeypatching of warnings before it exits.

@bedevere-app
Copy link

bedevere-app bot commented Jan 16, 2025

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.

@terryjreedy
Copy link
Member

This probably should have a blurb and whoever merges may require one.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to use exec()? Can the tests simply use local classes as other deprecated() tests? Is it necessary to create an instance of the deprecated class?

@srinivasreddy
Copy link
Contributor Author

srinivasreddy commented Jan 21, 2025

  1. bug occurs only when we run help(<module name>), in order to simulate separate module i have used exec. We cannot use classes in test cases because a class assumes __module__ of its containing test file. I am open to use other simpler approaches.
  2. For the first test case CODE_SIMPLE, yes it is required to create an instance. For the second it is not required.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since test_warnings already has been converted to a package, and there is a subpackage data, it can be easy to add a file with deprecated classes.

I can reproduce the original issue without creating an instance of the class.

@Viicos
Copy link
Contributor

Viicos commented Jan 21, 2025

Alternatively, this can be fixed in pydoc, by accounting for methods without a __module__:

class A:
    def __new__(cls): pass

A.__new__.__module__ = None

# pydoc on A fails

warnings.deprecated just so happens to wrap object.__new__ which doesn't have a __module__, but the TypeError encountered in the issue can also happen in other cases.

… module and simplify the test that removes the need for exec function
@srinivasreddy
Copy link
Contributor Author

@serhiy-storchaka Done. Pls review again

@serhiy-storchaka
Copy link
Member

Alternatively, this can be fixed in pydoc, by accounting for methods without a __module__:

You are right. This is a more correct way to fix this issue.

See #129177.

@srinivasreddy
Copy link
Contributor Author

@serhiy-storchaka Nice. Can we close this PR?

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

Successfully merging this pull request may close these issues.

5 participants