This is a snippet from the python codebase, written by a type nazi
SessionInfoType = Union[AuthzQuerySessionInfo, AuthnReqSessionInfo]
Notice how it is doing a union of two objects. Do you know what those 2 objects are? Those are types as well. They have no business use case.
AuthzQuerySessionInfo = TypedDict(
"AuthzQuerySessionInfo",
{"name_id": Any, "came_from": Any, "issuer": Any, "not_on_or_after": Any, "authz_decision_info": Any,},
total=False,
)
AuthnReqSessionInfo = TypedDict(
"AuthnReqSessionInfo",
{
"ava": Union[dict, None],
"name_id": Any,
"came_from": Any,
"issuer": Text,
"not_on_or_after": Union[int, bool],
"authn_info": list,
"session_index": Any,
},
total=False,
)
RequestCookieType = TypedDict(
"RequestCookieType",
{
"request_id": Text,
"came_from": Optional[Text],
"public_id": Text,
"is_mobile": Union[Literal[True], Text],
"c_challenge": Text,
"c_challenge_method": Text,
},
total=False,
)
So now. not only do we have dicts that represent above data, we also have TypedDicts created specially for types.
To rub salt on the wound, the callsite with these types now looks like
session_info = authresp.session_info()
session_info = cast(SessionInfoType, session_info)
WTF!! If we have to see a codebase littered with TypedDicts just to satisfy type annotations and then have to cast everything to that type - why not just wrap it in a class and call it a day?
When I see garbage like this, I seriously question the productivity improvement brought about by python type annotations. I certainly end up spending an inordinate amount of time unraveling nested unions of types all over now. Considering switching to a team that uses Golang.