rouille•

Looks like a hack to be honest :/. That kind of things should be caught during code review. Next step for me would be using some kind of linter. Rewriting the AST like they do makes it look like they have their own special version of python.

1
ubernostrumyes, you can have a pony•

The article links to the Python documentation for how they do this, but the tl;dr is you can write custom handlers ("loaders" and "finders") and register them to be used whenever Python encounters an import statement. This gives you pretty much absolute control over how the import statement works, and lets you do things like the AST analysis and preprocessing mentioned in the article.

This does not require a custom Python interpreter; the extensibility/configurability of import behavior has been a standard feature since Python 2.3.

3
rouille•

I don't mean this requires a custom interpreter but more like a custom dialect. E.g. classes being slotted implicitly. Why not use something like attrs(sloted=True).

1