A request for IntelliSense for pygame and suggestion feature, which is not currently there for it.
Right now doing ctrl + space didn't give any suggestions for this library.
@Bipul-Harsh I think this was mistriaged. We already ship type stubs for pygame so you should be seeing completions/IntelliSense. Do you have an example of where you weren't seeing IntelliSense?
Also are you using the Pylance language server?
Pylance is installed.
actually after creating file
for below line as example
import pygame
window = pygame.display.set_mode((500,500))
on writing pygame.display. and then
But with jupyter notebook in vscode
On importing pygame module by running import statement at first
it give suggestion on writing in next block
so i think it only works when you first import the pygame library in jupter notebook
please consider checking the above case yourself.
I've looked at the stub; the ones we bundle do not explicitly export the submodules, but it appears that upstream is implying that they do not need to be imported directly and that importing pygame is enough.
As a workaround, you can explicitly write import pygame.display, and then display will be present.
Should I keep this issue open? Till the bug not get fixed.
And thanks, for your suggestion.
Yes, this is a bug in the stubs we ship, so we'll fix them.
ok thanks
this is a bug in the stubs we ship
@jakebailey pygame has maintained type definitions. I wonder why pylance specific ones necessary?
Jake, @illume is correct. I just installed the latest version of pygame, it it has built-in type stubs, and they're relatively high-quality stubs at that. The library is marked as "py.typed".
When I use pyright's "--verifytypes" command, it indicates that it is 80.2% type complete, which is relatively high.
Public symbols: 3012
Symbols with unknown type: 595
Functions with missing docstring: 616
Functions with missing default param: 14
Classes with missing docstring: 51
Type completeness score: 80.2%
With a small amount of work, we could probably get it close to 100%.
Here's what I managed to achieve after about five minutes of fixing some obvious errors (adding missing imports in some stubs, making examples module private, etc.):
Public symbols: 2525
Symbols with unknown type: 136
Functions with missing docstring: 551
Functions with missing default param: 14
Classes with missing docstring: 43
Type completeness score: 94.6%
I recommend that we no longer bundle pygame stubs with pylance. We can eliminate our (incomplete) copy of the pygame stubs and contribute any further improvements to the pygame repo.
Thanks. I believe we wrote and bundled these stubs many months ago, probably before pygame's were mature, so we could drop them if upstream is doing well.
Hm, I'm testing this with pygame==2.0.1 before I delete our stubs and I get a different (worse) result:
Public symbols: 11414
Symbols with unknown type: 3481
Functions with missing docstring: 1744
Functions with missing default param: 14
Classes with missing docstring: 190
Type completeness score: 69.5%
Were you testing with a dev version?
Hmm, I installed the latest version from pypi and used that for my test.
Is it 2.0.1? I tested on Linux and Windows, and got identical results (even with pyright from master, just to really check). Maybe there's some difference on Macs (and I'll pull mine out).
EDIT: 2.0.1 on my mac is identical to the above.
In any case, pygame 2.0 is the first py.typed version and the 70% coverage is much better than the ~6% coverage that the old version had, which I believe is what we had stubbed.
Pygame 2.0.1 ships with a bunch of tests. I renamed the test directory to _test before I ran the type verifier. That accounts for the difference in what we're seeing.
The next release drops the pygame stubs; upgrading to pygame 2.0+ brings in types (and as far as I can tell, 2.0 is backwards compatible with v1 by design).
This issue has been fixed in version 2021.3.3, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202133-24-march-2021
i think intellisense part is still not working as by only importing pygame and after pygame.display. <ctrl><space> it still says no suggestions.
Please consider doing it yourself.
And thanks to all of you for your support to my issue. 😊
The pygame authors have written their type stubs to indicate that submodules like display are not re-exported from the top-level pygame module. That means you would need to use import pygame.display or from pygame.display import x to access the display submodule.
If you think that these submodules should be re-exported from the top-level module, you should contact the maintainers of pygame and ask them to make that change — or see if they would be willing to accept a PR.
Here's the change that you'd need to make within __init__.pyi:
import pygame.display
needs to be changed to...
from . import display as display
PEP 484 indicates that the former statement means a local import only, whereas the second means "import and re-export from this module".
ok i will do the method you suggested, leaving it here. Thanks
I needed something to do that wasn't staring at matplotlib stubs, so I fixed all of the issues in pygame and sent over https://github.com/pygame/pygame/pull/2537.
Most helpful comment
I needed something to do that wasn't staring at matplotlib stubs, so I fixed all of the issues in pygame and sent over https://github.com/pygame/pygame/pull/2537.