Y
Hacker News
new
|
ask
|
show
|
jobs
by
parhamn
252 days ago
Whats the expected error in the example you gave? That x can't be none because it was received as a str?
4 comments
robertlagrant
252 days ago
Yes, exactly. x would have to be str | None to be reachable.
link
pawelkobojek
252 days ago
Exactly - something along the lines of "Statement is unreachable".
link
wiz21c
252 days ago
isn't it perfectly valid to pass None to that function ? It's not like python enforces types at runtime nor at compile time. Right ?
link
yesb
252 days ago
Sure, it's valid python to do that. By that logic you could also pass an int. But the context of this post is that you're using a static type checker.
link
Austizzle
252 days ago
It's not valid from a typing perspective, but python will let you. If you want to disregard types though then none of this matters anyway and you won't get much benefit from these tools
link
boxed
252 days ago
Or that x is unused?
link