drawbot icon indicating copy to clipboard operation
drawbot copied to clipboard

VScode IntelliSense doesn't work in the suggested examples.

Open setanarut opened this issue 3 years ago • 18 comments

VScode IntelliSense doesn't work that way. (official example)

import drawBot

drawBot.newDrawing()
drawBot.newPage(1000, 1000)
drawBot.rect(10, 10, 100, 100)
drawBot.saveImage("~/Desktop/aRect.png")
drawBot.endDrawing()

VScode IntelliSense works that way. Would using it this way cause a problem? I'm not an expert, just wondering. Ekran Resmi 2021-10-18 21 18 31

setanarut avatar Oct 18 '21 18:10 setanarut

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?

justvanrossum avatar Oct 18 '21 18:10 justvanrossum

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. Ekran Resmi 2021-10-18 22 16 12 .

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())

setanarut avatar Oct 18 '21 19:10 setanarut

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.

justvanrossum avatar Oct 18 '21 19:10 justvanrossum

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.

justvanrossum avatar Oct 18 '21 19:10 justvanrossum

Unless it's caused by a missing __all__ = ...: it would be worth a try to add that.

justvanrossum avatar Oct 18 '21 19:10 justvanrossum

Oh you mean, if you don't use _drawBotDrawingTool as db but plain import drawBot as db. Right?

yes.

setanarut avatar Oct 18 '21 19:10 setanarut

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.

justvanrossum avatar Oct 18 '21 20:10 justvanrossum

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.

no

setanarut avatar Oct 18 '21 20:10 setanarut

"no" as in "VS doesn't pick it up", or "no" to "Can you try"?

justvanrossum avatar Oct 18 '21 20:10 justvanrossum

"no" as in "VS doesn't pick it up", or "no" to "Can you try"?

VS doesn't pick it up

setanarut avatar Oct 18 '21 20:10 setanarut

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...)

justvanrossum avatar Oct 18 '21 20:10 justvanrossum

I am not a developer. I know Python on a basic level. I was just guessing. You know better.

setanarut avatar Oct 18 '21 20:10 setanarut

Ok, let's leave this open in case anyone wants to pick it up.

justvanrossum avatar Oct 18 '21 20:10 justvanrossum

import drawBot
print(dir(drawBot)) # works

adding __all__ would simple addition

typemytype avatar Oct 19 '21 09:10 typemytype

(adding __all__ doesn't help — I am assuming VS does static code analysis)

justvanrossum avatar Oct 19 '21 09:10 justvanrossum

👋

I am using VSCode quite often with drawBot, I'll try to get a look into this!

roberto-arista avatar Apr 04 '22 11:04 roberto-arista

cc @lianghai

roberto-arista avatar Apr 04 '22 14:04 roberto-arista

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?

lianghai avatar Apr 04 '22 14:04 lianghai

@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.

bennettzug avatar Nov 16 '22 19:11 bennettzug

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

roberto-arista avatar Nov 17 '22 10:11 roberto-arista