Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyDev doesn't recognize the __package__ attribute

PyDev code analysis understands the special __file__ and __name__ attributes but __package__ gets flagged as undefined variable. Is this a missing feature, by design, or user error?

like image 276
VladG Avatar asked Sep 07 '26 10:09

VladG


2 Answers

According to the PythonCompletionWithBuiltinsPython3Test and PythonCompletionWithBuiltinsTest unit-tests inside the Pydev github repository, it seems that it supports builtin __file__, __name__, __init__, __dict__, __path__ but ignores __package__ and some other variables.

I've tested that myself using the PyDev extension in the VSCode and got a similar response:

enter image description here

But, there is a feature called Forced Builtins which for my VSCode PyDev plugin was set automatically as follows (also you can set it according the link I've mentioned):

enter image description here

However, it appears that the __package__ variable is still not recognized. Actually, it helps me in the auto-completion but after writing, it gives an Undefined variable: __package__ error.

like image 74
Alireza Roshanzamir Avatar answered Sep 10 '26 00:09

Alireza Roshanzamir


As a workaround add __package__ to Consider the following names as globals: (comma separated) field in Eclipse Preferences / PyDev / Editor / Code Analysis / Undefined.

like image 22
saaj Avatar answered Sep 10 '26 01:09

saaj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!