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

Create astroid module from a string using AstroidManager #725

Closed
twmr opened this issue Nov 20, 2019 · 2 comments · Fixed by #754
Closed

Create astroid module from a string using AstroidManager #725

twmr opened this issue Nov 20, 2019 · 2 comments · Fixed by #754
Labels
Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors

Comments

@twmr
Copy link
Contributor

twmr commented Nov 20, 2019

For the read-from-stdin feature in pylint an AST is constructed using

AstroidBuilder(MANAGER).string_build(data, modname, filepath)

whereas for regular modules it is constructed using

MANAGER.ast_from_file(filepath, modname, source=True)

See the get_ast method in https://github.com/PyCQA/pylint/pull/3257/files/5b24700e7bf84d1f2ae6fcd468acf5a9f6f1c458

The module docstring of astroid.manager suggests that the Manager should be used for both cases in pylint.

Therefore, AstroidManager should provide a way to create an AST from a string.

@twmr twmr changed the title Refactor AstroidManager/AstroidBuilder create astroid repr from strings using AstroidManager Nov 20, 2019
@PCManticore
Copy link
Contributor

Thanks for opening an issue @Thisch ! This is a matter of exposing a new ast_from_string API in AstroidManager which can look like:

    def ast_from_string(self, data, modname="", path=None):
        """Build astroid from source code string."""
        from astroid.builder import AstroidBuilder

        return AstroidBuilder(self).string_build(data, modname, path=path)

Is this something that you'd be interested in working on?

@PCManticore PCManticore added Good first issue Friendly and approachable by new contributors Enhancement ✨ Improvement to a component labels Nov 21, 2019
@PCManticore PCManticore changed the title create astroid repr from strings using AstroidManager Create astroid module from a string using AstroidManager Nov 21, 2019
@twmr
Copy link
Contributor Author

twmr commented Nov 27, 2019

Currently not. I'll wait a bit and work on it if no one else volunteers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants