Alice Averlong🏳️⚧️ on Nostr: ugh I haven't done enough python typing (stuck on 2.x for too long) to know how to do ...
ugh I haven't done enough python typing (stuck on 2.x for too long) to know how to do this. I have this code:
def blah(arg: str):
...
def main(arg: str|None):
if arg is None:
raise SomeError
blah(arg)
this code should work at runtime, but the problem is that I'm running this through some typechecking linter (ty) which is (rightly) pointing out that blah doesn't take a "str|None" type, it takes a "str". But it doesn't know I ruled out the None.
How do I fix? like, cast arg to str
Published at
2026-08-12 20:59:20 UTCEvent JSON
{
"id": "ba930a6274e16cb7b1626da5c762082770a4a5cb08dff56649eea138779dea18",
"pubkey": "8d0c6793de7edd25b3e6fcfd2e4e9b301cec2c7e577a9dcf0247e64d7c3c737e",
"created_at": 1786568360,
"kind": 1,
"tags": [
[
"proxy",
"https://digipres.club/users/foone/statuses/117084544068446143",
"activitypub"
],
[
"client",
"Mostr",
"31990:6be38f8c63df7dbf84db7ec4a6e6fbbd8d19dca3b980efad18585c46f04b26f9:mostr",
"wss://relay.ditto.pub"
]
],
"content": "ugh I haven't done enough python typing (stuck on 2.x for too long) to know how to do this. I have this code:\n\ndef blah(arg: str):\n ...\ndef main(arg: str|None):\n if arg is None:\n raise SomeError\n blah(arg)\n\nthis code should work at runtime, but the problem is that I'm running this through some typechecking linter (ty) which is (rightly) pointing out that blah doesn't take a \"str|None\" type, it takes a \"str\". But it doesn't know I ruled out the None.\n\nHow do I fix? like, cast arg to str",
"sig": "97f96884033a2cb59f6eeb207cc346678f0e1418b8f5397144da5e4b4761b6424fab00772be2d8ebeac6ce92bfae3887486c9c7ca85a896de1ac7536109c58ad"
}