You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Recursive sequence type of Sequence[NotAString] should not accept str #18184
This works as expected (even if surprising) because str is a subclass of Sequence[str]. As an exercise, try writing a code where an actual runtime error happens because of this behavior (the point is that you can't).
This works as expected (even if surprising) because str is a subclass of Sequence[str].
but str is not assignable to Scalar
edit: your argument assumes an infinite horizon, but within the context of typing, I think that a finite horizon would be more appropriate, analogous to how there's also a limit on the recursion depth at runtime
edit edit: if you'd parametrize str on its length then that will allow you to define an inductive basecase as str[1], and Sequence[str[1]] otherwise; so there's also no need for an infinite horizon
@ilevkivskyi I also feel like this is a Mypy issue. I am passing AFAIK all of Mypy's relevant recursion tests (except the ones with --disable-recursive-aliases) and this case seems to behave correct in my implementation.
Activity
ilevkivskyi commentedon Nov 24, 2024
This works as expected (even if surprising) because
stris a subclass ofSequence[str]. As an exercise, try writing a code where an actual runtime error happens because of this behavior (the point is that you can't).implement a workaround for python/mypy#18184
jorenham commentedon Nov 24, 2024
but
stris not assignable toScalaredit: your argument assumes an infinite horizon, but within the context of typing, I think that a finite horizon would be more appropriate, analogous to how there's also a limit on the recursion depth at runtime
edit edit: if you'd parametrize
stron its length then that will allow you to define an inductive basecase asstr[1], andSequence[str[1]]otherwise; so there's also no need for an infinite horizonjorenham commentedon Nov 24, 2024
jorenham commentedon Nov 25, 2024
FYI, this works as expected in pyright:
https://pyright-play.net/?strict=true&code=GYJw9gtgBAxmA28CmMAuBLMA7AzgOgEMAjGKdCABzBFSgGUkBHAVySxiQChRIpUBPCuiwBzMpWq0AKoKQBBeOgI5OnGPGU56MAhpAAuKHmOqAailTVDMivMXKoAXnpNW7JAG06OvQF1OUmw4VlA2dkpazuZo1FAAPi4sbBweAESBuNSp-pwEMBwUqEgAJgD6AG4WIdGWIE5QXj4EIAAUAJS%2BUF1dAMR8IKxQWEgiBBiVnCBIAFYWJRVVBlA1sc6pxcwwANap3Xu9-YNUOOjjSIYb21rNbADktJUxICq5%2BUiF80WZSxnBdc4eQHeXTNdq%2BcFQPqoAZIIYjMboCZTWZoT5BagARms6P%2BUDARBRqHa%2B0hh1hx1OiPOeIJFmuUyw9z4OJUyLmZS%2BfwATNjvvV1psdiSDsBdDhYcNRmcLoL6bDOdR8MYAPycIA
davidhalter commentedon Nov 25, 2024
@ilevkivskyi I also feel like this is a Mypy issue. I am passing AFAIK all of Mypy's relevant recursion tests (except the ones with
--disable-recursive-aliases) and this case seems to behave correct in my implementation.jorenham commentedon Nov 25, 2024
@KotlinIsland any thoughts on this?
KotlinIsland commentedon Nov 26, 2024
I think its consistent with the concept/spec, but impractical... maybe. I think pyright is wrong/inconsistent here...
let's change how it works in basedmypy 🚀🚀🚀