python - Prevent PyDev from moving specific imports -
python - Prevent PyDev from moving specific imports -
while programming under eclipse+pydev , using flask framework, noticed auto-organizing imports feature ide (invoked ctrl+o) gets in way.
this related way flask deals need of splitting views code multiple modules, or packages. basically, if have views.py
module contains request handlers:
from myapp import app @app.route('/') def root(): homecoming "hello world"
and flask app defined in __init__.py
:
from flask import flask app = flask('myapp') app.config.from_pyfile('config.py') @app.before_request def before_request(): pass # omitted brevity @app.teardown_request def teardown_request(): pass # omitted brevity
you need import views
at end of latter file view functions added flask's routing table. since views.py
imports __init__.py
access app
variable, results in circular import. works fine, though, , in fact established practice, suggested documentation.
unfortunately, pydev knows nil technique. should accidentally trigger organizing imports __init__.py
(not uncommon, given how useful alternative in general), pydev happily move crucial import views
top. of course, results in wrong (irresolvable) circular import, , annoying runtime error.
is there way prevent happening - #@directive
tell pydev leave specific import alone, way turn off import organizing on per-file basis, or similar?
i don't utilize pydev, have tried throwing off import parser? dirty, seek like:
if 1: import views
since line doesn't begin "import", maybe pydev pass over?
python pydev flask
Comments
Post a Comment