Coder Social home page Coder Social logo

Comments (9)

pablogsal avatar pablogsal commented on August 16, 2024 5

I can take a look this weekend 👍

from cpython.

Eclips4 avatar Eclips4 commented on August 16, 2024 2

Hmm...... But I'm trying to call a function outside the class. Why should it "mangled"? Shouldn't it happen only I am trying to get a class method?

In an ideal world, yes. But how do we determine that some lookups inside the class body are class-specific? These slow down performance due to additional lookups and just slightly increase user experience. To summarize, just don't name your functions with double leading underscores. :)

from cpython.

pablogsal avatar pablogsal commented on August 16, 2024 2

Yeah they normally go in tandem. I will let you know what we decide here once I have some time to play with this

from cpython.

Eclips4 avatar Eclips4 commented on August 16, 2024

This is intended behaviour. Explanation: https://docs.python.org/3.12/faq/programming.html#i-try-to-use-spam-and-i-get-an-error-about-someclassname-spam.

from cpython.

PC-Killer avatar PC-Killer commented on August 16, 2024

from cpython.

PC-Killer avatar PC-Killer commented on August 16, 2024

from cpython.

Eclips4 avatar Eclips4 commented on August 16, 2024

That's perhaps the best solution:) But, could the interpreter tell the user the problem when it show the error? I don't think showing error needs to be as fast as possible :)

Yes, that's sounds reasonable for me.

from cpython.

Eclips4 avatar Eclips4 commented on August 16, 2024

cc @pablogsal Do you think it's worth improving the error message for "NameError" in such cases?

from cpython.

SweetyAngel avatar SweetyAngel commented on August 16, 2024

I want to extend this issue.
This code:

def __a():
    print("A")


class A:
    def b(self):
        self.__a()


a = A()
a.b()

throws another error:

AttributeError: 'A' object has no attribute '_A__a'

If NameError is planning to be improved, this should be also fixed

from cpython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.