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 — Typo hint message for from-imports? · Issue #91058 · python/cpython

Typo hint message for from-imports? #91058

New issue
Copy link
New issue
Copy link
Closed
Closed
Typo hint message for from-imports?#91058
Copy link
Labels
3.11only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedtype-featureA feature request or enhancementA feature request or enhancement

Description

Jean-Abou-Samra
mannequin
opened on Mar 2, 2022
Issue body actions
BPO 46902
Nosy @aroberge, @pablogsal, @jean-abou-samra

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2022-03-02.20:42:20.452>
labels = ['interpreter-core', 'type-feature', '3.11']
title = 'Typo hint message for from-imports?'
updated_at = <Date 2022-03-03.01:54:35.713>
user = 'https://github.com/Jean-Abou-Samra'

bugs.python.org fields:

activity = <Date 2022-03-03.01:54:35.713>
actor = 'pablogsal'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2022-03-02.20:42:20.452>
creator = 'Jean_Abou_Samra'
dependencies = []
files = []
hgrepos = []
issue_num = 46902
keywords = []
message_count = 2.0
messages = ['414385', '414398']
nosy_count = 3.0
nosy_names = ['aroberge', 'pablogsal', 'Jean_Abou_Samra']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue46902'
versions = ['Python 3.11']

  • PR: gh-91058: Add what's new entry for the improvement in commit 7cfbb49fcd4c85f9bab3797302eadf93df490344 #99198

Activity

  1. Jean-Abou-Samra commented on Mar 2, 2022

    @Jean-Abou-Samra
    Jean-Abou-Samramannequin
    on Mar 2, 2022
    MannequinAuthor
    More actions

    See for example:

    >>> from pygments.regexopt import regexopt
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: cannot import name 'regexopt' from 'pygments.regexopt' (/home/jean/repos/pygments/pygments/regexopt.py)
    >>> from pygments.regexopt import regex_opt
    >>> regexopt
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'regexopt' is not defined. Did you mean: 'regex_opt'?

    In Python 3.10, there is a nice helpful error message suggesting
    how to correct the typo for NameError and AttributeError. Would
    it be possible to have the same for ImportError with 'from import'?

  2. Jean-Abou-Samra
    added
    3.10 (EOL)end of lifeend of life
    3.11only security fixesonly security fixes
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    type-featureA feature request or enhancementA feature request or enhancement
    on Mar 2, 2022
  3. AlexWaygood
    removed
    3.10 (EOL)end of lifeend of life
    on Mar 2, 2022
  4. pablogsal commented on Mar 3, 2022

    @pablogsal
    pablogsal
    on Mar 3, 2022
    Member
    More actions

    I evaluated this, but is considerably more complex than the regular import, because one triggers an attribute error where we have the full module but in the second case we don't have the full module ready, so it requires considerable modifications.

    I will investigate again if there is a way that doesn't require lots of changes, but is likely that we unfortunately need to reject this improvement :(

  5. ezio-melotti
    transferred this issue fromon Apr 10, 2022
  6. erlend-aasland commented on Aug 16, 2022

    @erlend-aasland
    erlend-aasland
    on Aug 16, 2022
    Contributor
    More actions

    Pablo's reply hints that the added complexity would not be worth it. I suggest to consider closing this as rejected, unless Pablo found a less complex way :)

  7. erlend-aasland
    added
    pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
    on Aug 16, 2022
  8. aroberge commented on Aug 16, 2022

    @aroberge
    aroberge
    on Aug 16, 2022
    Contributor
    More actions

    Perhaps it is doable within CPython without too much added code since is something that friendly_traceback can do.

    [1]: from pygments.regexopt import regexopt
    
    Traceback (most recent call last):
      Code block [1], line 1
        from pygments.regexopt import regexopt
    ImportError: cannot import name 'regexopt' from 'pygments.regexopt'
    (C:\Users\Andre.Roberge\AppData\Local\Programs\Python\Python310\lib\site-packages\pygments\regexopt.py)
    
    Did you mean regex_opt?
    
    [2]: why()
    
    Perhaps you meant to import regex_opt (from pygments.regexopt) instead of regexopt
    
    [3] import sys;
    
    [4] 'pygments' in sys.modules
    True
    
  9. pablogsal commented on Aug 18, 2022

    @pablogsal
    pablogsal
    on Aug 18, 2022
    Member
    More actions

    @aroberge You comment shows that friendly_traceback does it but unfortunately, it doesn't mention how you are proposing us to do it so we cannot evaluate the solution :( Could you add a brief sketch of how you are doing it in friendly_traceback?

  10. aroberge commented on Aug 18, 2022

    @aroberge
    aroberge
    on Aug 18, 2022
    Contributor
    More actions

    @pablogsal friendly_traceback looks at the list of modules found in sys.modules and, if the desired module is found, it proceeds from there.

    The relevant code starts at:
    https://github.com/friendly-traceback/friendly-traceback/blob/cdf87b1a623c4afcab4ad869eb29fe885e2d0621/friendly_traceback/runtime_errors/import_error.py#L104

    Perhaps the way that the information available to friendly_traceback after an exception has been raised is not yet available to CPython at that point, but I thought I should mention this possibility.

  11. pablogsal commented on Aug 18, 2022

    @pablogsal
    pablogsal
    on Aug 18, 2022
    Member
    More actions

    @pablogsal friendly_traceback looks at the list of modules found in sys.modules and, if the desired module is found, it proceeds from there.

    The relevant code starts at: friendly-traceback/friendly-traceback@cdf87b1/friendly_traceback/runtime_errors/import_error.py#L104

    Perhaps the way that the information available to friendly_traceback after an exception has been raised is not yet available to CPython at that point, but I thought I should mention this possibility.

    The problem with this approach is that if we do this every time the interpreter raises an ImportError we will slow down the interpreter when someone is catching said exception and continuing so they will have to pay an important (unbounded) cost for a message they won't see. That is what I am trying to circumvent. We cannot also install any exception hooks because of bootstrapping problems and because the interpreter needs to raise them without executing Python in some scenarios.

    Reacted by Erlend E. Aasland
  12. aroberge commented on Aug 18, 2022

    @aroberge
    aroberge
    on Aug 18, 2022
    Contributor
    More actions

    Understood; most Python users (myself included) do appreciate this emphasis on speed. Those requiring better traceback analysis can use third-party packages, like friendly_traceback.

    Reacted by Erlend E. Aasland
  13. erlend-aasland commented on Aug 18, 2022

    @erlend-aasland
    erlend-aasland
    on Aug 18, 2022
    Contributor
    More actions

    Yeah, I think this approach is not very useful for CPython. A lot of stdlib modules try to import their C implementation first, else fall back to a Python implementation. I think we can safely close this.

  14. erlend-aasland
    closed this as not plannedon Aug 18, 2022
  15. pablogsal
    reopened this on Oct 15, 2022
  16. pablogsal
    added a commit that references this issue on Oct 15, 2022

    pythongh-91058: Add error suggestions to 'import from' import errors

    21e36fc
  17. pablogsal commented on Oct 15, 2022

    @pablogsal
    pablogsal
    on Oct 15, 2022
    Member
    More actions

    The fairy of error messages is back! ✨

    I found a way to implement this without penalty to control-flow failed imports that are quite clean IMHO:

    #98305

    Thanks @aroberge for suggesting the idea in the first place. Good things come to those who wait apparently :)

    Reacted by Erlend E. Aasland, Zac Hatfield-Dodds and Oleh Rybalchenko
  18. pablogsal
    added a commit that references this issue on Oct 17, 2022

    pythongh-91058: Add error suggestions to 'import from' import errors

    a35c5ac
  19. pablogsal
    added a commit that references this issue on Oct 25, 2022

    gh-91058: Add error suggestions to 'import from' import errors (#98305)

    7cfbb49
  20. pablogsal
    closed this as completedon Oct 25, 2022
  21. pablogsal
    added 2 commits that reference this issue on Nov 7, 2022

    pythongh-91058: Add what's new entry for the improvement in commit 7c…

    bd0c9e4

    gh-91058: Add what's new entry for the improvement in commit 7cfbb49 (#…

    be31ecf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.