Skip to content

Add types for zxcvbn - #8089

Merged
JelleZijlstra merged 7 commits into
python:masterfrom
srittau:zxcvbn
Jun 21, 2022
Merged

JelleZijlstra merged 7 commits into
python:masterfrom
srittau:zxcvbn

Conversation

@srittau

@srittau srittau commented Jun 16, 2022

Copy link
Copy Markdown
Collaborator

No description provided.

@github-actions

This comment has been minimized.

Comment thread stubs/zxcvbn/zxcvbn/__init__.pyi Outdated
@srittau srittau mentioned this pull request Jun 17, 2022
5 of 6 tasks

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mostly looks good, but I'm not sure about the huge _Match TypedDict in matching.pyi. It seems like we could probably have a smaller base TypedDict, and return subtypes of that TypedDict from specific functions where _Match always has certain other keys.

Comment thread stubs/zxcvbn/zxcvbn/time_estimates.pyi Outdated
Comment thread stubs/zxcvbn/zxcvbn/matching.pyi Outdated
Comment thread stubs/zxcvbn/zxcvbn/matching.pyi Outdated
@srittau

srittau commented Jun 18, 2022

Copy link
Copy Markdown
Collaborator Author

Mostly looks good, but I'm not sure about the huge _Match TypedDict in matching.pyi. It seems like we could probably have a smaller base TypedDict, and return subtypes of that TypedDict from specific functions where _Match always has certain other keys.

Basically everything except the zxcvbn() function in __init__.py is internal API anyway, so I wouldn't want to put the work in for a finer-grained API.

srittau added 2 commits June 18, 2022 16:46
Theorically, this supports more types, but I don't think that's important here.
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@srittau

srittau commented Jun 20, 2022

Copy link
Copy Markdown
Collaborator Author

Ideally we'd be able to return DateMatch | DictionaryMatch | ..., but I don't think type checkers support discriminating result by typed dict field (pattern in this case).

@github-actions

This comment has been minimized.

@AlexWaygood

Copy link
Copy Markdown
Member

What do you want to do here?

  1. Wait until pyre/pytype have PEP 655 support?
  2. Rewrite the PR to use TypedDict inheritance for now?
  3. YOLO it and go with PEP 655 even though pytype/pyre don't fully support it yet?

@srittau

srittau commented Jun 20, 2022

Copy link
Copy Markdown
Collaborator Author

I honestly think, we could just merge it. pytype should just assume Any if I understand pytype's type handling correctly. We can wait for pyre support, but on the other hand this is a new package, so it not working for a few weeks is not a regression.

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few small comments

Comment thread stubs/zxcvbn/zxcvbn/__init__.pyi Outdated
Comment thread stubs/zxcvbn/zxcvbn/__init__.pyi Outdated
Comment thread stubs/zxcvbn/zxcvbn/matching.pyi Outdated
Comment thread stubs/zxcvbn/zxcvbn/scoring.pyi Outdated
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra
JelleZijlstra merged commit 678c231 into python:master Jun 21, 2022
@srittau
srittau deleted the zxcvbn branch June 21, 2022 11:36
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.

3 participants