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

HTMLDependency(script=) should allow for a list of strings #40

Open
cpsievert opened this issue Jun 16, 2022 · 1 comment
Open

HTMLDependency(script=) should allow for a list of strings #40

cpsievert opened this issue Jun 16, 2022 · 1 comment

Comments

@cpsievert
Copy link
Collaborator

cpsievert commented Jun 16, 2022

Same goes for HTMLDependency(stylesheet=)

Not only is it less typing, but it's also annoying to have to remember when to use src vs href (and >95% of the time you don't need any extra attributes)

@wch
Copy link
Collaborator

wch commented Jun 17, 2022

FWIW, I very recently added better typing information so that VS Code will underline in red if the shape of the input isn't correct.

image

Since this is code that's almost never used by normal users, I don't think that saving a bit of typing is that much of a benefit.

I really don't want to end up in a place similar to HTML dependencies in R, where so many forms of input are accepted, and we've spent countless hours trying to understand the shape of the data, and it's very painful and risky to make any changes. (I'm thinking of this one we dealt with very recently, where it took hours just to fix a small recursive function, because the shape of the data was unclear.)

We currently allow a dict or a list of those dicts. So the inputs could look like these:

script = {"src": "foo.js"}

script = [{"src": "foo.js"}]

script = [{"src": "foo.js"}, {"src": "bar.js", "type": "module"}]

If we also allow bare strings, then the inputs could look like this:

script = "foo.js"

script = {"src": "foo.js"}

script = [{"src": "foo.js"}]

script = ["foo.js", {"src": "bar.js", "type": "module"}]

script = ["foo.js"]

script = [{"src": "foo.js"}, {"src": "bar.js", "type": "module"}]

If there's one thing I know, it's that when people are allowed to use inputs in a particular way, they will use them that way, so all of these forms will end up in the wild. The nature of this kind of library code is that it is read much more often than it is written, and so if the inputs are loose, in the long run it will result in people spending much more time trying to decipher other people's code than it will save them in typing and remembering which field names are needed (especially now that the type hints help with the field names).

I know it may seem like I'm reacting strongly to this... it's in part because we recently spent hours trying to understand and fix up a simple PR in R htmltools that should have been trivial. Every time we work with HTML dependencies in R, it is way, way more painful than it should be, largely because we've been very lax with the inputs, and even worse, we've used those varied inputs directly in our data structures. (Thankfully, we're not doing the latter in Python!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants