mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-08 04:54:48 +08:00
Make CharField(blank=True) not be considered nullable (#39)
* Make CharField(blank=True) not be considered nullable The documentation on [blank](https://docs.djangoproject.com/en/2.1/ref/models/fields/#blank) says that it "will allow the entry of an empty value", which for a string is just a 0-length string. This patch allows `CharField(blank=True,...)` to no longer be considered `Optional`. closes #38 * fixed tests for `CharField(blank=True)` * allow blank CharField to be nullable in the constructor, but the underlying type is str (unless `null=True`)
This commit is contained in:
committed by
Maxim Kurnikov
parent
627daa55f5
commit
f7dfbefbd6
@@ -183,6 +183,13 @@ def extract_expected_types(ctx: FunctionContext, model: TypeInfo,
|
||||
False):
|
||||
field_type = helpers.make_optional(field_type)
|
||||
|
||||
# if CharField(blank=True,...) and not nullable, then field can be None in __init__
|
||||
elif (
|
||||
helpers.has_any_of_bases(typ.type, (helpers.CHAR_FIELD_FULLNAME,)) and is_init and
|
||||
field_metadata.get('blank', False) and not field_metadata.get('null', False)
|
||||
):
|
||||
field_type = helpers.make_optional(field_type)
|
||||
|
||||
expected_types[name] = field_type
|
||||
|
||||
return expected_types
|
||||
|
||||
Reference in New Issue
Block a user