Add IDE autocomplete for known html attributes#111
Add IDE autocomplete for known html attributes#111gazpachoking wants to merge 9 commits intopelme:mainfrom
Conversation
|
Looks like my type checking tests must have been too loose. I'll investigate further. EDIT: Crap. My tests were totally flawed. I was testing a script using htpy, not the codebase itself. This error makes sense to me, and I was sorta wondering why it was fine. Not sure I can come up with a good solution though. |
|
Well, closer maybe. PEP 728 does what we want for this, which allows us to type the attr dict as well as the kwargs. It also allows tightening the typing on class_ vs other attributes. typing_extensions has provisional support for this, which I switched to here, as does pyright. pyright now passes on the main codebase, but for some reason doesn't like it when passing extra arguments in, still not sure what's up with that, whether it's just incomplete pep 728 support or something else. Unless there's some other way to get this to work I think we have to wait for more support of PEP 728. |
|
Nice, I think this is the way to go. We just need to wait for PEP 728 to land and for mypy/pyright to add support for it. |
|
Pyright started supporting PEP 728 for this purpose after I put in this ticket, so that bit seems to work. microsoft/pyright#10352 This looks like the issue to watch for mypy support: python/mypy#18176 It would be super cool if this feature got added to allow us to make Components generic based on a TypedDict. Then each tag could declare which attributes were valid for that particular tag. python/typing#1399 |
|
Now I'm wondering if this would be better as an IDE extension. Ideally it would recognize the context of being in an htpy element, and provide the auto completions from the native HTML language completer. (With a couple rewrites like class_) |
Not sure if this is the best way to do this, but it's the easiest way I found in my testing. Would be sorta nice to have it only autocomplete the valid attributes for a given tag, but I haven't found a clean way to accomplish that. Cursory tests seem to indicate pyright and mypy are both fine with unknown attributes being passed in still. Autocomplete was tested in PyCharm, haven't tested vscode.