@@ -559,3 +559,34 @@ def test_input_model_recursive_model_types(tmp_path: Path) -> None:
559559 output_path = tmp_path / "output.py" ,
560560 expected_output_contains = ["set[str]" , "value:" ],
561561 )
562+
563+
564+ @SKIP_PYDANTIC_V1
565+ def test_input_model_optional_set_type (tmp_path : Path ) -> None :
566+ """Test that Optional[Set[str]] is preserved when converting Pydantic model."""
567+ run_input_model_and_assert (
568+ input_model = "tests.data.python.input_model.pydantic_models:ModelWithPythonTypes" ,
569+ output_path = tmp_path / "output.py" ,
570+ expected_output_contains = ["set[str] | None" , "optional_set:" ],
571+ )
572+
573+
574+ @SKIP_PYDANTIC_V1
575+ def test_input_model_optional_set_to_typeddict (tmp_path : Path ) -> None :
576+ """Test that Optional[Set[str]] works when outputting to TypedDict."""
577+ run_input_model_and_assert (
578+ input_model = "tests.data.python.input_model.pydantic_models:ModelWithPythonTypes" ,
579+ output_path = tmp_path / "output.py" ,
580+ extra_args = ["--output-model-type" , "typing.TypedDict" ],
581+ expected_output_contains = ["TypedDict" , "set[str] | None" , "optional_set:" ],
582+ )
583+
584+
585+ @SKIP_PYDANTIC_V1
586+ def test_input_model_union_none_frozenset (tmp_path : Path ) -> None :
587+ """Test that Union[None, FrozenSet[str]] is preserved (container not first arg)."""
588+ run_input_model_and_assert (
589+ input_model = "tests.data.python.input_model.pydantic_models:ModelWithPythonTypes" ,
590+ output_path = tmp_path / "output.py" ,
591+ expected_output_contains = ["frozenset[str] | None" , "nullable_frozenset:" ],
592+ )
0 commit comments