Closed setanarut closed 1 year ago
Not knowing what VS does, let alone IntelliSense, I somehow can't extract the problem from your description. What does not work? What do you expect to work?
What does not work?;
VScode IntelliSense doesn't work(Pylance) when import drawBot
What do you expect to work?; When I import the drawBot module I expect to reach the functions of the class with the dot. for example.
.
This issue is caused by the global namespace. https://github.com/typemytype/drawbot/blob/master/drawBot/__init__.py
from .drawBotDrawingTools import _drawBotDrawingTool
_drawBotDrawingTool._addToNamespace(globals())
When I import the drawBot module I expect to reach the functions of the class with the dot. for example.
But your first screenshot is showing exactly that, no? db.rect()
is indeed a method of the db
object.
Oh you mean, if you don't use _drawBotDrawingTool as db
but plain import drawBot as db
. Right?
Well, Python is a dynamic language, what we're doing is not uncommon or illegal. This is a weakness of the IntelliSense tool, not a bug with DrawBot.
Unless it's caused by a missing __all__ = ...
: it would be worth a try to add that.
Oh you mean, if you don't use _drawBotDrawingTool as db but plain import drawBot as db. Right?
yes.
Unless it's caused by a missing all = ...: it would be worth a try to add that.
Can you try to see whether that makes a difference? Adding just __all__ = ["rect"]
to drawBot/__init__.py
should be enough to see whether VS picks that up.
Unless it's caused by a missing all = ...: it would be worth a try to add that.
Can you try to see whether that makes a difference? Adding just
__all__ = ["rect"]
todrawBot/__init__.py
should be enough to see whether VS picks that up.
no
"no" as in "VS doesn't pick it up", or "no" to "Can you try"?
"no" as in "VS doesn't pick it up", or "no" to "Can you try"?
VS doesn't pick it up
Thanks.
A solution could be to generate that __init__.py
file from the drawing tools object during app build, in such a way that it can more easily be statically analyzed. The output could look like this snippet:
from .drawBotDrawingTools import _drawBotDrawingTool
def rect(...arguments all written out...):
"""...doc string....""" # copied from _drawBotDrawingTool.rect
_drawBotDrawingTool.rect(...arguments...)
I am not a developer. I know Python on a basic level. I was just guessing. You know better.
Ok, let's leave this open in case anyone wants to pick it up.
import drawBot
print(dir(drawBot)) # works
adding __all__
would simple addition
(adding __all__
doesn't help — I am assuming VS does static code analysis)
đź‘‹
I am using VSCode quite often with drawBot
, I'll try to get a look into this!
cc @lianghai
Instead of https://github.com/typemytype/drawbot/issues/440#issuecomment-946148489, simply doing—
from .drawBotDrawingTools import _drawBotDrawingTool
rect = _drawBotDrawingTool.rect
—should be good enough. But why is from drawBot import _drawBotDrawingTool as db
a problem at all? Since those functions are really indeed methods of DrawBotDrawingTool
, why should they be presented in a more confusing way?
@roberto-arista did you ever look into this? No worries if not, just don't want to start digging into something if you've already done a bunch of work towards it.
hey @bennettzug! not really, I am working in VSCode mostly using the import suggested above
from drawBot import _drawBotDrawingTool as db
and I find it quite ok
VScode IntelliSense doesn't work that way. (official example)
VScode IntelliSense works that way. Would using it this way cause a problem? I'm not an expert, just wondering.