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

AUTH_PASSWORD_VALIDATORS should support OPTIONS #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

syastrov
Copy link
Contributor

Django allows a Dict as the value for the key 'OPTIONS' inside of the list of validators in AUTH_PASSWORD_VALIDATORS.
See https://docs.djangoproject.com/en/2.2/topics/auth/passwords/#enabling-password-validation

The type annotation is currently overly strict.
Although, it is possible to be more specific with TypedDict, the key 'OPTIONS' is not required to be present, and there is no way to represent that currently, so I have used Union.

I have made things!

Related issues

Django allows a Dict as the value for the key 'OPTIONS' inside of the list of validators in AUTH_PASSWORD_VALIDATORS.
See https://docs.djangoproject.com/en/2.2/topics/auth/passwords/#enabling-password-validation

The type annotation is currently overly strict.
Although, it is possible to be more specific with TypedDict, the key 'OPTIONS' is not required to be present, and there is no way to represent that currently, so I have used Union.
@mkurnikov mkurnikov closed this Nov 12, 2019
@mkurnikov mkurnikov reopened this Nov 12, 2019
@mkurnikov mkurnikov added this to the 1.3.0 milestone Nov 12, 2019
@syastrov
Copy link
Contributor Author

Actually, I found out that it is possible to represent TypedDicts with non-required fields: https://mypy.readthedocs.io/en/latest/more_types.html#mixing-required-and-non-required-items

You have to do something like this:

class AuthPasswordValidatorsDictBase(TypedDict):
  NAME: str

class AuthPasswordValidatorsDict(AuthPasswordValidatorsDictBase, total=False):
  OPTIONS: Dict[str, Any]

Is it OK to use TypedDict in the stubs?

@sobolevn
Copy link
Member

@syastrov totally fine by me!

@mkurnikov
Copy link
Member

I think Literal and TypedDict should be fine for 1.3.0 version, PyCharm hopefully would catch-up by then. Thank you=)

@mkurnikov mkurnikov removed this from the 1.3.1 milestone Dec 12, 2019
voidus pushed a commit to voidus/django-stubs that referenced this pull request Apr 23, 2024
Pyright 1.1.339 enabled reportIncompatibleVariableOverride=true as part of new default "standard" mode.

https://github.com/microsoft/pyright/releases/tag/1.1.339

This leads to

> error: "Meta" overrides symbol of same name in class "Model"

At runtime, models do not have `Meta` if it's not defined, so it's safe to remove it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants