Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration should not use attributes starting with __ to not run into name mangling options. #174

Closed
MaxOstrowski opened this issue Nov 4, 2019 · 7 comments
Assignees
Milestone

Comments

@MaxOstrowski
Copy link
Member

I found a mismatch in the Configuration interface when using python.
If this is due to my lacking python skills I'm very sorry.

The following example is given in the API documentation to read the description of the configuration interface:

import sys
import clingo

prg = clingo.Control()
print(prg.configuration.solve.__desc_models)

When using the clingo_main method using an Application

import sys
import clingo

class Application:
    def main(self, prg, files):
        print(prg.configuration.solve.__desc_models)

sys.exit(int(clingo.clingo_main(Application(), sys.argv[1:])))

I do get the following error:

print(prg.configuration.solve.__desc_models)

AttributeError: 'clingo.Configuration' object has no attribute '_Application__desc_models'

@rkaminsk
Copy link
Member

rkaminsk commented Nov 4, 2019

Strange. Somehow the name gets mangled. I'll look into it later...

import sys
import clingo

def test(cfg):
    print (cfg.__desc_models)

class Application:
    def main(self, prg, files):
        #print(prg.configuration.solve.__desc_models)
        print (getattr(prg.configuration.solve, "__desc_models"))
        print (test(prg.configuration.solve))

sys.exit(int(clingo.clingo_main(Application(), sys.argv[1:])))

@rkaminsk rkaminsk self-assigned this Nov 4, 2019
@rkaminsk rkaminsk added the bug label Nov 4, 2019
@rkaminsk rkaminsk added this to the v5.4.1 milestone Nov 4, 2019
@peschue
Copy link

peschue commented Nov 4, 2019

Double underscore is always mangled to make the symbol private and unaccessible from the "outside", e.g., in derived classes. As far as I know, calling such methods is only possible from a method in the same class, not from outside (and calling from a derived class counts as outside).

@rkaminsk rkaminsk removed the bug label Nov 4, 2019
@rkaminsk rkaminsk removed this from the v5.4.1 milestone Nov 4, 2019
@rkaminsk
Copy link
Member

rkaminsk commented Nov 4, 2019

Yes, you are right. I was thinking the name mangling is applied based on the type of the target object but this is not the case. So there is no bug. It was just a bad idea to prefix the __desc_* attributes with __ because they are actually not private variables.

@Aluriak
Copy link

Aluriak commented Nov 5, 2019

For reference, the symbol is not unaccessible. You may access it using ._Application__desc_models. This is not an interdiction to call private members but a way to avoid the need for subclasses to know the implementation details of mother classes.

@peschue
Copy link

peschue commented Nov 6, 2019

Thank you!

rkaminsk added a commit that referenced this issue Dec 2, 2019
Replace __desc* attribute in python and lua api with a description
function. The __desc attributes are kept for backward compatibility.
@rkaminsk
Copy link
Member

rkaminsk commented Dec 2, 2019

There is now a description method. Have a look at the example along with the commit.

@rkaminsk rkaminsk closed this as completed Dec 2, 2019
@rkaminsk rkaminsk changed the title Python Application Interface Configuration should not use attributes starting with __ to not run into name mangling options. Dec 2, 2019
@rkaminsk rkaminsk added this to the v5.4.1 milestone Dec 2, 2019
@MaxOstrowski
Copy link
Member Author

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants