pep8, autopep8 and imports at the end of file

577 views Asked by At

I'm using Eclipse with plugged autopep8 and I found it it very helpful. It's saving a lot of my time from fixing code style by hands. But for some coding patterns I don't know how to avoid pep8 rules I don't want to use. For example using Django (1.5.4) I need to connect signals of installed application. I always use import signals at the end of models.py file. But pep8 doesn't allow to use imports at end of file. # noqa comment doesn't helps. I can not put import signals to the top of the models.py file, because in signals I use some models still not defined on that moment.

What can you suggest in this situation? May be there is more appropriate way to connect signals?

1

There are 1 answers

0
Daniel Roseman On

Firstly, everything in PEP8 is a recommendation, not a hard-and-fast rule. If your code needs a certain structure, you should feel free to ignore the recommendation.

That said, importing signals at the end of your models file feels a bit strange. Rather, import both models and signals from a separate file that is itself imported at startup. The app's __init__.py file might be a good candidate, or you can use the new AppConfig functionality in 1.7.