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 — Improve NameError error suggestion for instances · Issue #99139 · python/cpython

Improve NameError error suggestion for instances #99139

New issue
Copy link
New issue
Copy link
Closed
Closed
Improve NameError error suggestion for instances#99139
Copy link
Labels
3.12only security fixesonly security fixestype-featureA feature request or enhancementA feature request or enhancement

Description

@pablogsal
pablogsal
opened on Nov 5, 2022
Issue body actions

If we are in a method and a NameError is raised for the name X, first check if X is an attribute of the instance as self.X is likely more common than whatever closest match we find in the scope.

  • PR: gh-99139: Improve NameError error suggestion for instances #99140
Reacted by Ewout ter Hoeven, Jordan Levy, Petr Messner, rzehumat and Jose Angel Sanchez Castillejos

Activity

  1. pablogsal
    added a commit that references this issue on Nov 5, 2022

    pythongh-99139: Improve NameError error suggestion for instances

    01650df
  2. hauntsaninja commented on Nov 6, 2022

    @hauntsaninja
    hauntsaninja
    on Nov 6, 2022
    Contributor
    More actions

    This is great! I learnt C++ before Python so I used to forget self all the time when I first started programming in Python. Thank you!

    Reacted by Pablo Galindo Salgado and Giusekk
  3. kumaraditya303
    added
    type-featureA feature request or enhancementA feature request or enhancement
    3.12only security fixesonly security fixes
    on Nov 6, 2022
  4. pablogsal
    added a commit that references this issue on Nov 6, 2022

    gh-99139: Improve NameError error suggestion for instances (#99140)

    99e2e60
  5. pablogsal
    closed this as completedon Nov 6, 2022
  6. sobolevn commented on Nov 6, 2022

    @sobolevn
    sobolevn
    on Nov 6, 2022
    Member
    More actions

    Looks awesome! Lots of begginers going to love that!

    What about a case like:

    class Some:
       x = 1
       @classmethod 
       def method(cls):
           x + 2  # Should be cls.x

    Do we care to support it? 🤔

  7. pablogsal commented on Nov 6, 2022

    @pablogsal
    pablogsal
    on Nov 6, 2022
    MemberAuthor
    More actions

    Looks awesome! Lots of begginers going to love that!

    What about a case like:

    class Some:
    
       x = 1
    
       @classmethod 
    
       def method(cls):
    
           x + 2  # Should be cls.x

    Do we care to support it? 🤔

    Thanks for the proposal!

    I will consider it but is unlikely that will happen as we are not interested in supporting all possible variations of this, specially since the name of the variable here (cls) is less standardised than "self" and is less common.

    Also, this will force us to distinguish the type of function to avoid inspecting random variables called "cls".

    Reacted by sobolevn
  8. EwoutH commented on Nov 7, 2022

    @EwoutH
    EwoutH
    on Nov 7, 2022
    More actions

    Thanks for this, and improving error messages in general!

    Reacted by Pablo Galindo Salgado
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.12only security fixesonly security fixestype-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.