How to decrease the type checking paranoia? #1629
-
I've been trying to have my code as clear as possible in terms of typing suggestions but I always end up ignoring a few of them to prevent the code quality violation, the one that most annoys me is this example below. I'm writing one API service then usually what I do is:
From this part, I'm already making sure that this variable cannot be None, but when I import this constant in another file that I may have or not use it as an argument I always end up with something like...
So my point is I don't want to check if these constants are None on every piece of code that I need to use, so maybe I'm not sure if I'm doing it properly or indeed we need some extra, extra, extra value validation before using it... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Maybe create a helper function like this: def env_not_none(key: str) -> str:
value = os.getenv(key)
assert value is not None, f"failed to find {key}"
return value
CONNECTION_STRING = env_not_none("CONNECTION_STRING") |
Beta Was this translation helpful? Give feedback.
Maybe create a helper function like this: