-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make sydent.terms
pass mypy --strict
#428
Conversation
Shout out to getForClient, which a) mixes presentation with data and b) was a massive PITA to type hint. It's very very stringly typed. Part of #414
|
||
# Ensure we're dealing with unicode. | ||
if version and isinstance(version, bytes): | ||
version = version.decode("UTF-8") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused why its safe to remove the bytes check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
version
comes fromself._rawTerms
self._rawTerms
is a dict, set in the constructor. I can't see anywhere that it's mutated.- It'll be set to either None or
yaml.safe_load(...)
- AFAIK the latter can't produce a
bytes
object....
But that last bullet isn't correct. There's a !!binary
"language independent scalar type" in YAML. So I guess it's possible that this could be a bytes object.
I am incredibly tempted to just pull in jsonschema
and use that to enforce the config shape and type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...but I've refrained and checked the string type after we load the yaml.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, that works. In general the flow is a bit weird here as we validate the data, then pass around the dict and then pull out data from it, which means its quite hard to see what has been validated and what hasn't. But let's not fix that up in a typing PR.
Part of #414
I was sad to get rid of the
TypedDict
fromsydent.db.invite_tokens
, but given that we immediately use it by adding extra keys, it wasn't worth the effort. Oh well.