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
Actually, would it be a bad idea to replace the Anys with None in that case? Otherwise, in my use case, I'll have to cast the return value as list[str | None] myself.
Having None in the return value would likely cause many false positives, since often the caller can predict that there will only be strings. That's why the | Any was there in the first place instead of | None.
It would be good to add a comment explaining the Any types, as otherwise this will continue to cause confusion.
Activity
JelleZijlstra commentedon May 24, 2022
They're there because the list entries can be None:
Though this behavior doesn't appear to be documented: https://docs.python.org/3.10/library/re.html#re.split
GrantGryczan commentedon May 25, 2022
Huh, alright then. Strange that it isn't documented.
GrantGryczan commentedon May 25, 2022
Actually, would it be a bad idea to replace the
Anys withNonein that case? Otherwise, in my use case, I'll have tocastthe return value aslist[str | None]myself.JukkaL commentedon May 25, 2022
Having
Nonein the return value would likely cause many false positives, since often the caller can predict that there will only be strings. That's why the| Anywas there in the first place instead of| None.It would be good to add a comment explaining the
Anytypes, as otherwise this will continue to cause confusion.AlexWaygood commentedon May 25, 2022
@srittau has proposed #7870 to tackle this problem in a more general way; we're currently
bikesheddingdebating the appropriate name for the feature.