From f6d167e921fa3c96274a73bd4adea77f6f501c2b Mon Sep 17 00:00:00 2001 From: Thibaut Decombe Date: Mon, 18 Aug 2025 09:38:16 +0200 Subject: [PATCH] Add failing test for strict_optional=False --- tests/typecheck/fields/test_nullable.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/typecheck/fields/test_nullable.yml b/tests/typecheck/fields/test_nullable.yml index 8d06476ba..d7d74fecd 100644 --- a/tests/typecheck/fields/test_nullable.yml +++ b/tests/typecheck/fields/test_nullable.yml @@ -49,6 +49,27 @@ text_nullable = models.CharField(max_length=100, null=True) text = models.CharField(max_length=100) +- case: nullable_field_with_strict_optional_false + main: | + from myapp.models import MyModel + reveal_type(MyModel().text_nullable) # N: Revealed type is "builtins.str | None" + installed_apps: + - myapp + mypy_config: | + [mypy] + strict_optional = True + + [mypy-myapp.*] + strict_optional = False + files: + - path: myapp/__init__.py + - path: myapp/models.py + content: | + from django.db import models + class MyModel(models.Model): + text_nullable = models.CharField(max_length=100, null=True) + + - case: nullable_array_field main: | from myapp.models import MyModel