At Home:
On the go:
I wrote my own scripts to tag the music and encode it to FLAC and Opus and use syncthing to copy the files to my phone. So whenever I add an album to the library it will be available every where I want in the specified format without any manual copying involved. It’s a little janky but has worked surprisingly well for years.
python -m http.server
came in handy so many times!
Maybe something like passing in a list of patterns which should match some data, or a list of files/urls to download would be examples of where I would like to be generic, but taking in a string would be bad.
But the real solution be to convert it to foo(*args: str)
. But maybe if you take 2 Container[str]
as input so you can’t use . But no real world example comes to mind.
This + an assert seems like the way to go. I think that str
should never have fulfilled these contracts in the first place and should have a .chars
property that returns a list of one-character-strings.
But this change would break existing code, so it is not going to happen.
str
matches most of these contracts, though, requiring additional checks if a str
was passed or one of these collections containing strings.
But what if you actually don’t want str
to be valid?
I know that Iterable
and Collection
aren’t the same. My point is, that if you use Iterable[str]
or Collection[str]
as a more flexible alternative to list[str]
you no longer have any type-hinting support protecting against passing in a plain string and you could end up with a subtle bug by unexpectedly looping over ['f', 'o', 'o']
instead of ['foo']
.
Don’t do this. Running unpatched software is a recipe for disaster.
What’s your hoster?