Replies: 1 comment 1 reply
-
I remember |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In python one can iterate over a
str
as if it was aList[str]
. And while this is occasionaly useful it can also be a major footgun if users pass in a"string"
instead of a["string"]
and suddenly have a function operate on single characters instead of the whole string, as they might (admittedly, errouniously) assumed one that one string.In python I'd prevent this user error by ensuring incoming str are never treated as a list of characters by wrapping a lone
str
in a list as follows:In pyo3 this is an issue as well. Let's say i have a simple function that should take a
Vec<String>
and print out each string in the vec:If I now run this in the python interpreter with a string that is not a list each character is printed out seperately:
Is there any simple way to ensure single
str
are treated as[str]
using pyo3? Even an Error would be acceptable, as long as users don't pass a string and have it iterate over characters without them noticing.Beta Was this translation helpful? Give feedback.
All reactions