Skip to content
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

Merged
merged 4 commits into from
Oct 20, 2021
Merged

Make sydent.terms pass mypy --strict #428

merged 4 commits into from
Oct 20, 2021

Conversation

DMRobertson
Copy link
Contributor

Part of #414

I was sad to get rid of the TypedDict from sydent.db.invite_tokens, but given that we immediately use it by adding extra keys, it wasn't worth the effort. Oh well.

David Robertson added 2 commits October 15, 2021 19:13
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")
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • version comes from self._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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@DMRobertson DMRobertson merged commit 5de7349 into main Oct 20, 2021
@DMRobertson DMRobertson deleted the dmr/mypy-terms branch October 20, 2021 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants