Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

Improve NameError error suggestion for instances #99139

Closed

Description

@pablogsal

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.

Activity

  1. added a commit that references this issue on Nov 5, 2022
  2. hauntsaninja commented on Nov 6, 2022

    @hauntsaninja
    Contributor

    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!

  3. added a commit that references this issue on Nov 6, 2022
  4. sobolevn commented on Nov 6, 2022

    @sobolevn
    Member

    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? 🤔

  5. pablogsal commented on Nov 6, 2022

    @pablogsal
    MemberAuthor

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

  6. EwoutH commented on Nov 7, 2022

    @EwoutH

    Thanks for this, and improving error messages in general!

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 fixestype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions