Remove starred imports

Starred imports are generally considered bad practice. Could we please get rid of them in the default code that’s currently generated for any form?


I worry that this sort of thing (like also making it difficult to follow PEP8) gives certain python programmers a negative first impression of Anvil.

Even if the default remains the same, I would like to be able to configure the imports auto-generated for new forms/modules.

1 Like

When I create a new form the only starred import I get is from anvil import *

I honestly would not want to see all couple dozen anvil imports listed out separately. I’m perfectly happy importing them into the form namespace with a star.

Now, if the editor allowed code folding at the import level so all the imports could be hidden, and had an auto-import mechanism (e.g. the first time I type out TextBox it adds from anvil import TextBox automatically), then I could get behind not doing the star import for anvil.

… and it had code completion before importing.

You wouldn’t need to list them. You can just do

import anvil

And then, if you needed an alert, you call


You could even use an alias

import anvil as av



Pep8 gives a description of why either of these options is preferred to a wildcard (as do many other articles online).


Yes, of course. Implied was that I don’t want the extra typing, either. I like the convenience of having the anvil functions in the form namespace.

So if the default were import anvil, I’d change that to the starred import in my forms right off. A configuration toggle such as @hugetim suggested would help with that.

1 Like

I second this. Starred imports were one of the first things I learned to avoid when learning Python.