Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Auto completion of private methods #1154

Closed

Description

@lauevrar77

Hello,

I'm writing this issue for something that may be an error in the auto completion (it may also be a design choice) but when I create __something() private methods (or attributes), they are auto completed to _ClassName__something().

I known python internally do this transformation at runtime however, the behavior that I expected is to have this method (or attribute) auto-completed to __something().

Here is an example :
Capture d’écran 2019-06-03 à 05 51 56

Activity

  1. jakebailey commented on Jun 3, 2019

    @jakebailey
    Member

    I found this the other day, you beat me to reporting it. 😃

  2. MikhailArkhipov commented on Jun 3, 2019

    @MikhailArkhipov

    Here when class is analyzed, LS handles class data member declarations, then the constructor. In this case constructor declares remote_id via self.remote_id = remote_id, which then conflicts with def remote_id. We'd need to see what exactly class members are in this case. Generally current code assumes that all class members have unique names.

  3. lauevrar77 commented on Jun 3, 2019

    @lauevrar77
    Author

    I don't think it is linked to a conflict of name here. The problem also appear with simpler examples :

    Capture d’écran 2019-06-03 à 07 22 51

    In my previous example remote_id became a property setter afterward.

    Also, if I select this for completion, it's actually completed to _Test__foo not to the correct value so it may not be "just" a bad tooltip.

  4. MikhailArkhipov commented on Jun 3, 2019

    @MikhailArkhipov

    This looks by design. Parser generates this name according to
    https://docs.python.org/3/tutorial/classes.html#private-variables

    where __foo becomes _ClassName__foo.

    Any identifier of the form __spam (at least two leading underscores, at most one trailing underscore) is textually replaced with _classname__spam, where classname is the current class name with leading underscore(s) stripped. This mangling is done without regard to the syntactic position of the identifier, as long as it occurs within the definition of a class.

    https://stackoverflow.com/questions/1301346/what-is-the-meaning-of-a-single-and-a-double-underscore-before-an-object-name

    Having said that... Agree that it kinda makes it hard to use private variables with self...

  5. lauevrar77 commented on Jun 3, 2019

    @lauevrar77
    Author

    I know that python use this renaming convention to make private attributes or methods private at runtime (dynamic behavior) but during the implementation (static behavior), isn't it more sound to auto-complete with the approriate (static behavior) value ?

  6. MikhailArkhipov commented on Jun 3, 2019

    @MikhailArkhipov

    Yes, agreed. What needs to change is

    • presentation layer, i.e. show original, unmangled name.
    • linter, so it does not confuse mangled and unmangled names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions