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 — pydoc.safeimport: Use importlib.import_module instead of __import__ by ppwwyyxx · Pull Request #103118 · python/cpython

Conversation

@ppwwyyxx

@ppwwyyxx ppwwyyxx commented Mar 29, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Some libraries behave a bit differently:

$ import torch.optim.sgd   # success
$ torch.optim.sgd
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 torch.optim.sgd

AttributeError: module 'torch.optim' has no attribute 'sgd'

For such modules, safeimport fails to import the module because it tries to access the attribute "sgd". On the other hand, importlib.import_module can do it correctly.
Using import_module also simplifies code.

Sorry, something went wrong.

Uh oh!

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

arhadthedev reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@ppwwyyxx
pydoc.locate: Use importlib.import_module instead of __import__
6c275b8
@bedevere-bot bedevere-bot added the awaiting review label Mar 29, 2023
@arhadthedev arhadthedev added skip issue skip news stdlib Standard Library Python modules in the Lib/ directory labels Mar 31, 2023
@arhadthedev arhadthedev removed a link to an issue Apr 7, 2023
MANAGER CREDENTIALS #103345
Closed
@ppwwyyxx

ppwwyyxx commented Apr 10, 2023

Copy link
Copy Markdown
Contributor Author

Can I get a reviewer assigned?

All reactions

Sorry, something went wrong.

Uh oh!

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

@arhadthedev

arhadthedev commented Apr 11, 2023

Copy link
Copy Markdown
Member

@iritkatriel (as a more-than-once committer into Lib/pydoc.py last year still active)

All reactions

Sorry, something went wrong.

Uh oh!

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

@iritkatriel

iritkatriel commented Apr 11, 2023

Copy link
Copy Markdown
Member

Can I get a reviewer assigned?

That’s not how it works.

@arhadthedev - having committed to a script is not a good indication of ability to review any change in it.

I’m less concerned about being spammed with inappropriate review requests, than about creating false expectations among contributors who do not understand how this goes.

In this case it would be better to first reset the OP’s expectations about our process. If you are looking for a reviewer, I would start by looking for a pydoc maintainer, and if I can’t find one then an import expert.

arhadthedev, brettcannon, and AlexWaygood reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

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

@ppwwyyxx

ppwwyyxx commented Apr 11, 2023

Copy link
Copy Markdown
Contributor Author

Thanks for the explanation!
From https://devguide.python.org/core-developers/experts/ it seems there is no maintainer for pydoc - not sure if this is the correct place to find such info. But I can find importlib experts from this link.

All reactions

Sorry, something went wrong.

Uh oh!

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

@ppwwyyxx

ppwwyyxx commented Apr 12, 2023

Copy link
Copy Markdown
Contributor Author

@brettcannon You're listed as an import expert. Could you review this?

All reactions

Sorry, something went wrong.

Uh oh!

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

brettcannon
brettcannon approved these changes May 3, 2023
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels May 3, 2023
@brettcannon
brettcannon merged commit e95dd40 into python:main May 3, 2023
@bedevere-bot bedevere-bot removed the awaiting merge label May 3, 2023
@brettcannon

brettcannon commented May 3, 2023

Copy link
Copy Markdown
Member

@ppwwyyxx thanks!

ppwwyyxx and mokko reacted with heart emoji
All reactions
  • ❤️ 2 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

@brettcannon brettcannon brettcannon approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

skip issue skip news 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.

5 participants

@ppwwyyxx @arhadthedev @iritkatriel @brettcannon @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.