django-stubs icon indicating copy to clipboard operation
django-stubs copied to clipboard

Add missing py.typed File

Open max-muoto opened this issue 1 year ago • 8 comments

Currently the lack of a py.typed file means that in VSCode the default bundled Django stubs (derived from djagno-types) are prioritized). This can make it quite confusing (for Pyright users) why you're seeing different results when running the Pyright CLI versus Pyright's type-checking in VSCode.

For reference, one is present in Djagno-Types as well: https://github.com/sbdchd/django-types

max-muoto avatar Apr 27 '24 21:04 max-muoto

Sorry, I am not a pyright user. I cannot review :(

sobolevn avatar Apr 27 '24 21:04 sobolevn

Sorry, I am not a pyright user. I cannot review :(

Any other reviewers I could possibly ping?

max-muoto avatar Apr 27 '24 22:04 max-muoto

I don't use pyright either. Does this change affect any other type checker, if not, could we merge and try it out?

flaeppe avatar Apr 28 '24 15:04 flaeppe

in VSCode the default bundled Django stubs (derived from djagno-types) are prioritized).

According to PEP 561, stubs-only packages don't need to include py.typed.

Note that for stub-only packages adding a py.typed marker is not needed since the name *-stubs is enough to indicate it is a source of typing information.

Did you try that this actually fixes the issue?

I wasn't aware that VSCode or pyright bundle the django-types package. I'm willing to consider work-around hacks, but this is a problem caused by VSCode/pyright first and foremost. I think manually installed stubs should override the defaults. Please open an issue for them and see what they think. In any case, they are in a better position to suggest what the appropriate solution is.

intgr avatar Apr 28 '24 17:04 intgr

This is an existing issue on the Pylance side: https://github.com/microsoft/pylance-release/issues/5031, so indeed not related to the missing py.typed marker which is not required for stubs.

Viicos avatar Apr 30 '24 09:04 Viicos

From what I can tell, while it isn't required, it is a way of at least tricking Pylance into prioritizing it.

max-muoto avatar Apr 30 '24 15:04 max-muoto

OK, per issue linked by Viicos, this has been reported upstream and there hasn't been any progress for months.

But did you test that this solves the issue with django-stubs? Usually it's also needed to change setup.py to ensure py.typed is included in the package.

intgr avatar Apr 30 '24 16:04 intgr

some of stub packages bundeld in pylance is a partial stub. py.typed file in them indicate it is partial stub not full stub

See https://peps.python.org/pep-0561/#partial-stub-packages for more detail

That said it sounds like a bug in import resolution order around partial stubs. U should open an issue in pylance

heejaechang avatar Feb 06 '25 02:02 heejaechang