xpodev / seamless

A Python package for creating and manipulating HTML components. It is working similar to React.js, but in Python.
https://seamless.readthedocs.io
MIT License
11 stars 1 forks source link

split types/html.py to small files one per class #63

Closed elazarcoh closed 1 month ago

elazarcoh commented 1 month ago

move each props class to its own file. currently I named the files the same as the class name (PascalCase), but I can convert it to snake_case, just let me know your preference.

neriyaco commented 1 month ago

We prefer all imports to be relative, so the package can be self-contained.

Other than that it's great.

elazarcoh commented 1 month ago

That would defy the purpose of this PR, as I see it. My whole reason for me to split it to smaller chunks is that now I'm able to override a single typeddict class with my own additional properties. The way I'm doing it is by telling pyright to look for stubs in a local folder to my projects, e.g. typings. Now, I create a file named typings\seamless\types\html\html_element_props.pyi. In this file I'm creating my own version of HTMLElementProps, which have the additional properties I need.

You can see my usage here https://github.com/elazarcoh/seamless/tree/htmx-with-tailwind/examples/htmx specifically, https://github.com/elazarcoh/seamless/blob/htmx-with-tailwind/examples/htmx/typings/seamless/types/html/html_element_props.pyi and https://github.com/elazarcoh/seamless/blob/79bf682a52c14c22c9e34fa0ee78d15d7da921cb/examples/htmx/components/app.py#L42

neriyaco commented 1 month ago

I see, I'm trying to understand if this PR is a patch until the typing issue is fixed or it's more of a permanent solution that should be in the package.

elazarcoh commented 1 month ago

Actually, it's much more powerful than the __extra_items__ thing. It's more similiar to the thing with the TypeVar(..., bound=TypedDict) which does not have even a PEP. With this, the user has the ability to have precise auto-completion and static-type-checking, they just have to override with a stub.

neriyaco commented 1 month ago

It looks like something that's worth documenting, it can be great for projects that extend Seamless.

I'll test this PR tomorrow.

elazarcoh commented 1 month ago

Make sure to look at the example in the branch I mentioned

neriyaco commented 1 month ago

I did, might use it in the documentation.