Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pygame: bundled stubs do not reexport submodules #758

Closed
Bipul-Harsh opened this issue Dec 19, 2020 · 22 comments
Closed

pygame: bundled stubs do not reexport submodules #758

Bipul-Harsh opened this issue Dec 19, 2020 · 22 comments
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version typestub Issue relating to our bundled type stubs

Comments

@Bipul-Harsh
Copy link

Requesting for suggestion feature and intellisense for pygame.

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.

@brettcannon brettcannon transferred this issue from microsoft/vscode-python Dec 21, 2020
@github-actions github-actions bot removed the triage label Dec 21, 2020
@savannahostrowski
Copy link
Contributor

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

@savannahostrowski savannahostrowski added waiting for user response Requires more information from user and removed needs stub labels Feb 24, 2021
@Bipul-Harsh
Copy link
Author

Bipul-Harsh commented Feb 26, 2021

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 <ctrl+space> it says "no suggestions"

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

@Bipul-Harsh
Copy link
Author

please consider checking the above case yourself.

@jakebailey jakebailey added typestub Issue relating to our bundled type stubs and removed waiting for user response Requires more information from user labels Feb 26, 2021
@jakebailey
Copy link
Member

jakebailey commented Feb 26, 2021

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.

@jakebailey jakebailey changed the title Feature request for pygame pygame: bundled stubs do not reexport submodules Feb 26, 2021
@Bipul-Harsh
Copy link
Author

Should I keep this issue open? Till the bug not get fixed.

And thanks, for your suggestion.

@jakebailey
Copy link
Member

Yes, this is a bug in the stubs we ship, so we'll fix them.

@Bipul-Harsh
Copy link
Author

ok thanks

@illume
Copy link

illume commented Mar 21, 2021

this is a bug in the stubs we ship

@jakebailey pygame has maintained type definitions. I wonder why pylance specific ones necessary?

@erictraut
Copy link
Contributor

erictraut commented Mar 21, 2021

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.

@jakebailey
Copy link
Member

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.

@jakebailey
Copy link
Member

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?

@erictraut
Copy link
Contributor

Hmm, I installed the latest version from pypi and used that for my test.

@jakebailey
Copy link
Member

jakebailey commented Mar 22, 2021

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.

@jakebailey
Copy link
Member

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.

@erictraut
Copy link
Contributor

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.

@jakebailey jakebailey added type checking fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed type checking labels Mar 23, 2021
@jakebailey
Copy link
Member

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

@jakebailey
Copy link
Member

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

@Bipul-Harsh
Copy link
Author

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.

@Bipul-Harsh
Copy link
Author

And thanks to all of you for your support to my issue. 😊

@erictraut
Copy link
Contributor

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

@Bipul-Harsh
Copy link
Author

Bipul-Harsh commented Mar 25, 2021

ok i will do the method you suggested, leaving it here. Thanks

@jakebailey
Copy link
Member

I needed something to do that wasn't staring at matplotlib stubs, so I fixed all of the issues in pygame and sent over pygame/pygame#2537.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version typestub Issue relating to our bundled type stubs
Projects
None yet
Development

No branches or pull requests

6 participants