On Fri, 8 Apr 2022 at 11:26, Malthe <mborch@gmail.com> wrote:
Perhaps `some_regex = re::compile(r"...")` could work.
That is, <dotted-path>::<name-to-import> to delineate the import.
As I mentioned in the Discourse thread, this syntax chimes with Rust (and C++, and also PHP, triggering fond memories of Paamayim Nekudotayim). There are two problems, sort of on the minor side: First, there's one place in Python where this can occur and that is in slices: xs[start::step] means the slice from start to the end with a step of step. But xs[(module::name)] is currently a syntax error, so you could just require parentheses to disambiguate the case. Still, it is confusing if you write something slightly more complex like xs[1 + math::factorial(n)] and you get NameError: name 'math' is not defined. Secondly, it precludes importing just a module object, you have to import a name from a module. Maybe using a module object in an expression is niche and can be disregarded. Or a solution could be to allow an expression like (re::) to import a module object, which I guess we could get used to. Also fun would be to consider what ::name does - access to current globals without the global keyword? I think this discussion is better suited to the python-ideas mailing list, or the Discourse thread I linked earlier.