Morgan Wilde
Morgan Wilde

Reputation: 17333

PyDev displays undefined variable from import for 1 out of 2 vars

Issue

I have the following structure:

home.py
logic/brains/databeam.py

Inside databeam.py I have:

engine  = create_engine(databaseSettings(), pool_size = 20, max_overflow = 0)
Session = sessionmaker(bind = engine)
session = Session()

boom = 'boom'

And in home.py:

from logic.brains.databeam import session, boom

print session
print session.query()
print boom

Everything works as intended, but PyDev on eclipse shows me this:

red source

error message

This works when...

Instead of using from logic.brains.databeam import session as session, boom as boom, I do this:

import logic.brains.databeam
session = logic.brains.databeam.session
boom    = logic.brains.databeam.boom

But this seems untidy, is there a better way to show PyDev that the import works?

Upvotes: 1

Views: 3417

Answers (4)

gladd
gladd

Reputation: 35

Really simple script producing the same error in Eclipse 2019-09 with PyDev 8.1.0.202012051215:

import re
flag = re.ASCII

It seems PyDev isn't inferring things exported using globals().update(). The following is equivalent and works (in this case):

import re
flag = re.RegexFlag.ASCII

Upvotes: 2

Franck Dernoncourt
Franck Dernoncourt

Reputation: 83427

As a way to circumvent the issue, I used:

enter image description here

then a bunch of

enter image description here

and

enter image description here

will appear. To hide them:

enter image description here

Upvotes: 1

Spicko
Spicko

Reputation: 41

@Lars, I can not comment on previous post, so i will put my comment here. If you have an error "Undefined variable from import" like @Morgan Wilde had with query, you should put Warning on that option under tab Undefined not Imports.

Upvotes: 1

Morgan Wilde
Morgan Wilde

Reputation: 17333

A solution that I found to be reasonable is to suppress this type of error in PyDev altogether. I know this is not perfect, but far and away the best one I've come across.

How to change this setting:

pydev settings change

Upvotes: 1

Related Questions