VSCode shows an error while importing document object from pyscript module #2266
Replies: 8 comments 24 replies
-
I suggest providing a minimal example that shows the issue as that errors doesn't come from PyScript and it's not clear how you are using PyScript in general, how you bootstrap it, and so on, thanks. |
Beta Was this translation helpful? Give feedback.
-
This is a two part problem. One is because there is no The issue here is that if you use an editor that wants/expects Python type hints, they are not really available when writing the scripts that will use the |
Beta Was this translation helpful? Give feedback.
-
It's wonderful to see such collaboration and cooperation. You mention bringing such efforts under the PyScript org... happy to help. What do you have in mind? 👍 |
Beta Was this translation helpful? Give feedback.
-
I was thinking to use the same approach I have been working towards for MicroPython as a whole , and adapt it to fit the tools and usecase for PyScript
A sample PoC I built last year for MicroPython Basic page template:
Document with AutoAPI fragments mixed in :
Then there are two workflows: To update documentation :
###Stub publication: Publish a a stub-only package just for the pyscript module to PyPI Publication can be done the same tooling currently used to publish packages
Locationthe location for the stub files should be somewhere that
so It can be either
|
Beta Was this translation helpful? Give feedback.
-
I think the maintainers should decide where the stubs should be placed and maintained,
We also need to select a tool for mkdocs AutoAPI stub --> docs translations. Then we need to start doing the work perhaps we can discuss details during one of the calls to decide |
Beta Was this translation helpful? Give feedback.
-
OK. Since we needed a starting point, I have forked @gregersn's |
Beta Was this translation helpful? Give feedback.
-
I've created a PR that I'd like @gregersn to check: gregersn/pyscript-stubs#1 It simply adds a README, LICENSE and CODE_OF_CONDUCT (as required by the PyScript project). Greg, please do let me know if there's a problem here and we can figure out next steps. Otherwise, please add a comment to the PR referenced above saying you're OK with these additions, and then we can start work. 👍 |
Beta Was this translation helpful? Give feedback.
-
On Wed, Feb 5, 2025 at 8:04 AM Greger ***@***.***> wrote:
If I am going to start using typescript, I will probably be writing stubs for myself, if none are available, add to it as I use things. I can then either keep that to myself, or make it available.
That would be a cool contribution, Greger. Please share the stubs you
create, even if they are just a start. That's how Linus Torvalds built
Linux with the help of thousands!
Having some of it typed, like the upper imports, as "Any" is still better, to me, than having nothing. As explicitly saying that something could be anything is better than it just being "I don't know what this is, at all"
I disagree with that approach. It's better to leave code without type
hints than annotating with a lot of `Any` hints without much
consideration.
The reason is that `Any` defeats type analysis, but its effect is not
limited to the place where it is used. A single `Any` type hint can
spread around the typing graph via type inference, and has far
reaching effects disabling type checking throughout the codebase.
If we don't know how (or don't have the resources) to annotate
something it's better to leave it without annotation, perhaps adding a
#type: ignore directive to silence the type checker.
Making it just a stubs-package, might actually be the better option.
I agree!
Cheers,
Luciano
…--
Luciano Ramalho
| Author of Fluent Python (O'Reilly, 2015-2022)
| https://www.oreilly.com/library/view/fluent-python-2nd/9781492056348/
| Mastodon: @***@***.***
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The pyscript documentation says that your first line has to be
from pyscript import document
to make your python script interact with HTML elements. I did that in VSCode, but it saysImport "pyscript" could not be resolved Pylance (reportMissingImports)
. How do I resolve this matter?Beta Was this translation helpful? Give feedback.
All reactions