From 17b5ff42c1dd6a5ad01367f25da2fabf013fc5e2 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 7 Nov 2019 14:40:44 +0000 Subject: [PATCH] renaming docs examples (#972) * renaming docs examples * tweaks --- docs/build/exec_examples.py | 10 +++-- ...se_initvars.py => dataclasses_initvars.py} | 0 ...{ex_dataclasses.py => dataclasses_main.py} | 0 ...d_dataclasses.py => dataclasses_nested.py} | 0 ...py => dataclasses_post_init_post_parse.py} | 0 .../{ex_debug.py => devtools_main.py} | 0 ...xport_copy.py => exporting_models_copy.py} | 0 ...xport_dict.py => exporting_models_dict.py} | 0 ...clude1.py => exporting_models_exclude1.py} | 0 ...clude2.py => exporting_models_exclude2.py} | 0 ...iterate.py => exporting_models_iterate.py} | 0 ...xport_json.py => exporting_models_json.py} | 0 ...n_orjson.py => exporting_models_orjson.py} | 0 ...t_pickle.py => exporting_models_pickle.py} | 0 ...son_ujson.py => exporting_models_ujson.py} | 0 docs/examples/{example2.py => index_error.py} | 2 +- docs/examples/{example1.py => index_main.py} | 0 ...fig.py => model_config_alias_generator.py} | 0 ...ce.py => model_config_alias_precedence.py} | 0 ...es_config.py => model_config_dataclass.py} | 0 .../{config.py => model_config_main.py} | 0 docs/examples/{ex_abc.py => models_abc.py} | 0 .../{ex_construct.py => models_construct.py} | 0 ...t_field.py => models_custom_root_field.py} | 0 ...onversion.py => models_data_conversion.py} | 0 ...creation.py => models_dynamic_creation.py} | 0 ...tance.py => models_dynamic_inheritance.py} | 0 .../{errors1.py => models_errors1.py} | 0 .../{errors2.py => models_errors2.py} | 0 .../{errors3.py => models_errors3.py} | 0 .../{field_order.py => models_field_order.py} | 0 .../{generics.py => models_generics.py} | 0 ...cs-naming.py => models_generics_naming.py} | 0 .../{mutation.py => models_mutation.py} | 0 .../{orm_mode.py => models_orm_mode.py} | 0 ...ursive.py => models_orm_mode_recursive.py} | 0 docs/examples/{parse.py => models_parse.py} | 0 .../{recursive.py => models_recursive.py} | 0 .../{mypy_example.py => mypy_main.py} | 0 ...ken.py => postponed_annotations_broken.py} | 0 ...y => postponed_annotations_forward_ref.py} | 0 ...tions.py => postponed_annotations_main.py} | 0 ...notations_self_referencing_annotations.py} | 0 ...ed_annotations_self_referencing_string.py} | 0 ...orks.py => postponed_annotations_works.py} | 0 .../examples/{schema3.py => schema_custom.py} | 0 docs/examples/{schema1.py => schema_main.py} | 0 .../{schema2.py => schema_top_level.py} | 0 ...ts.py => schema_unenforced_constraints.py} | 0 .../{schema4.py => schema_with_example.py} | 0 .../{settings.py => settings_main.py} | 0 .../{bare_type_type.py => types_bare_type.py} | 0 .../examples/{boolean.py => types_boolean.py} | 0 .../{callable.py => types_callable.py} | 0 .../examples/{choices.py => types_choices.py} | 0 .../{ex_color_type.py => types_color.py} | 0 ...strained_types.py => types_constrained.py} | 0 ...tom_data_types.py => types_custom_type.py} | 0 .../{datetime_example.py => types_dt.py} | 0 .../{ex_typing.py => types_iterables.py} | 0 .../{ex_json_type.py => types_json_type.py} | 0 .../{literal1.py => types_literal1.py} | 0 .../{literal2.py => types_literal2.py} | 0 .../{literal3.py => types_literal3.py} | 0 ...number.py => types_payment_card_number.py} | 0 ..._secret_types.py => types_secret_types.py} | 0 .../{strict_types.py => types_strict.py} | 0 docs/examples/{type_type.py => types_type.py} | 0 ...type_correct.py => types_union_correct.py} | 0 ..._incorrect.py => types_union_incorrect.py} | 0 ..._properties.py => types_url_properties.py} | 0 ...{url_punycode.py => types_url_punycode.py} | 0 docs/examples/{urls.py => types_urls.py} | 0 docs/index.md | 6 +-- docs/mypy_plugin.md | 2 +- docs/usage/dataclasses.md | 8 ++-- docs/usage/devtools.md | 4 +- docs/usage/exporting_models.md | 18 ++++---- docs/usage/model_config.md | 8 ++-- docs/usage/models.md | 34 +++++++------- docs/usage/mypy.md | 2 +- docs/usage/postponed_annotations.md | 12 ++--- docs/usage/schema.md | 18 ++++---- docs/usage/settings.md | 2 +- docs/usage/types.md | 44 +++++++++---------- 85 files changed, 86 insertions(+), 84 deletions(-) rename docs/examples/{ex_post_init_post_parse_initvars.py => dataclasses_initvars.py} (100%) rename docs/examples/{ex_dataclasses.py => dataclasses_main.py} (100%) rename docs/examples/{ex_nested_dataclasses.py => dataclasses_nested.py} (100%) rename docs/examples/{ex_post_init_post_parse.py => dataclasses_post_init_post_parse.py} (100%) rename docs/examples/{ex_debug.py => devtools_main.py} (100%) rename docs/examples/{export_copy.py => exporting_models_copy.py} (100%) rename docs/examples/{export_dict.py => exporting_models_dict.py} (100%) rename docs/examples/{advanced_exclude1.py => exporting_models_exclude1.py} (100%) rename docs/examples/{advanced_exclude2.py => exporting_models_exclude2.py} (100%) rename docs/examples/{export_iterate.py => exporting_models_iterate.py} (100%) rename docs/examples/{export_json.py => exporting_models_json.py} (100%) rename docs/examples/{json_orjson.py => exporting_models_orjson.py} (100%) rename docs/examples/{export_pickle.py => exporting_models_pickle.py} (100%) rename docs/examples/{json_ujson.py => exporting_models_ujson.py} (100%) rename docs/examples/{example2.py => index_error.py} (86%) rename docs/examples/{example1.py => index_main.py} (100%) rename docs/examples/{alias_generator_config.py => model_config_alias_generator.py} (100%) rename docs/examples/{alias_precedence.py => model_config_alias_precedence.py} (100%) rename docs/examples/{ex_dataclasses_config.py => model_config_dataclass.py} (100%) rename docs/examples/{config.py => model_config_main.py} (100%) rename docs/examples/{ex_abc.py => models_abc.py} (100%) rename docs/examples/{ex_construct.py => models_construct.py} (100%) rename docs/examples/{custom_root_field.py => models_custom_root_field.py} (100%) rename docs/examples/{data_conversion.py => models_data_conversion.py} (100%) rename docs/examples/{dynamic_model_creation.py => models_dynamic_creation.py} (100%) rename docs/examples/{dynamic_inheritance.py => models_dynamic_inheritance.py} (100%) rename docs/examples/{errors1.py => models_errors1.py} (100%) rename docs/examples/{errors2.py => models_errors2.py} (100%) rename docs/examples/{errors3.py => models_errors3.py} (100%) rename docs/examples/{field_order.py => models_field_order.py} (100%) rename docs/examples/{generics.py => models_generics.py} (100%) rename docs/examples/{generics-naming.py => models_generics_naming.py} (100%) rename docs/examples/{mutation.py => models_mutation.py} (100%) rename docs/examples/{orm_mode.py => models_orm_mode.py} (100%) rename docs/examples/{orm_mode_recursive.py => models_orm_mode_recursive.py} (100%) rename docs/examples/{parse.py => models_parse.py} (100%) rename docs/examples/{recursive.py => models_recursive.py} (100%) rename docs/examples/{mypy_example.py => mypy_main.py} (100%) rename docs/examples/{postponed_broken.py => postponed_annotations_broken.py} (100%) rename docs/examples/{forward_ref.py => postponed_annotations_forward_ref.py} (100%) rename docs/examples/{postponed_annotations.py => postponed_annotations_main.py} (100%) rename docs/examples/{self_referencing_annotations.py => postponed_annotations_self_referencing_annotations.py} (100%) rename docs/examples/{self_referencing_string.py => postponed_annotations_self_referencing_string.py} (100%) rename docs/examples/{postponed_works.py => postponed_annotations_works.py} (100%) rename docs/examples/{schema3.py => schema_custom.py} (100%) rename docs/examples/{schema1.py => schema_main.py} (100%) rename docs/examples/{schema2.py => schema_top_level.py} (100%) rename docs/examples/{unenforced_constraints.py => schema_unenforced_constraints.py} (100%) rename docs/examples/{schema4.py => schema_with_example.py} (100%) rename docs/examples/{settings.py => settings_main.py} (100%) rename docs/examples/{bare_type_type.py => types_bare_type.py} (100%) rename docs/examples/{boolean.py => types_boolean.py} (100%) rename docs/examples/{callable.py => types_callable.py} (100%) rename docs/examples/{choices.py => types_choices.py} (100%) rename docs/examples/{ex_color_type.py => types_color.py} (100%) rename docs/examples/{constrained_types.py => types_constrained.py} (100%) rename docs/examples/{custom_data_types.py => types_custom_type.py} (100%) rename docs/examples/{datetime_example.py => types_dt.py} (100%) rename docs/examples/{ex_typing.py => types_iterables.py} (100%) rename docs/examples/{ex_json_type.py => types_json_type.py} (100%) rename docs/examples/{literal1.py => types_literal1.py} (100%) rename docs/examples/{literal2.py => types_literal2.py} (100%) rename docs/examples/{literal3.py => types_literal3.py} (100%) rename docs/examples/{payment_card_number.py => types_payment_card_number.py} (100%) rename docs/examples/{ex_secret_types.py => types_secret_types.py} (100%) rename docs/examples/{strict_types.py => types_strict.py} (100%) rename docs/examples/{type_type.py => types_type.py} (100%) rename docs/examples/{union_type_correct.py => types_union_correct.py} (100%) rename docs/examples/{union_type_incorrect.py => types_union_incorrect.py} (100%) rename docs/examples/{url_properties.py => types_url_properties.py} (100%) rename docs/examples/{url_punycode.py => types_url_punycode.py} (100%) rename docs/examples/{urls.py => types_urls.py} (100%) diff --git a/docs/build/exec_examples.py b/docs/build/exec_examples.py index 03b4b8b..58e5e5e 100755 --- a/docs/build/exec_examples.py +++ b/docs/build/exec_examples.py @@ -53,7 +53,8 @@ class MockPrint: def __call__(self, *args, file=None, flush=None): frame = inspect.currentframe().f_back.f_back.f_back if not self.file.samefile(frame.f_code.co_filename): - raise RuntimeError('print statement outside the example file') + # happens when index_error.py imports index_main.py + return s = ' '.join(map(to_string, args)) lines = [] @@ -76,7 +77,7 @@ def gen_ansi_output(): conv = Ansi2HTMLConverter() - input_file = EXAMPLES_DIR / 'ex_debug.py' + input_file = EXAMPLES_DIR / 'devtools_main.py' os.environ['PY_DEVTOOLS_HIGHLIGHT'] = 'true' p = subprocess.run((sys.executable, str(input_file)), stdout=subprocess.PIPE, check=True, encoding='utf8') html = conv.convert(p.stdout, full=False).strip('\r\n') @@ -130,6 +131,7 @@ def exec_examples(): file_text = no_print_intercept_re.sub('', file_text) mp = MockPrint(file) + mod = None with patch('builtins.print') as mock_print: if not no_print_intercept: mock_print.side_effect = mp @@ -139,8 +141,8 @@ def exec_examples(): tb = traceback.format_exception(*sys.exc_info()) error(''.join(e for e in tb if '/pydantic/docs/examples/' in e or not e.startswith(' File '))) - if not mod.__file__.startswith(str(EXAMPLES_DIR)): - error(f'module path not inside "{EXAMPLES_DIR}", name may shadow another module?') + if mod and not mod.__file__.startswith(str(EXAMPLES_DIR)): + error(f'module path "{mod.__file__}" not inside "{EXAMPLES_DIR}", name may shadow another module?') lines = file_text.split('\n') diff --git a/docs/examples/ex_post_init_post_parse_initvars.py b/docs/examples/dataclasses_initvars.py similarity index 100% rename from docs/examples/ex_post_init_post_parse_initvars.py rename to docs/examples/dataclasses_initvars.py diff --git a/docs/examples/ex_dataclasses.py b/docs/examples/dataclasses_main.py similarity index 100% rename from docs/examples/ex_dataclasses.py rename to docs/examples/dataclasses_main.py diff --git a/docs/examples/ex_nested_dataclasses.py b/docs/examples/dataclasses_nested.py similarity index 100% rename from docs/examples/ex_nested_dataclasses.py rename to docs/examples/dataclasses_nested.py diff --git a/docs/examples/ex_post_init_post_parse.py b/docs/examples/dataclasses_post_init_post_parse.py similarity index 100% rename from docs/examples/ex_post_init_post_parse.py rename to docs/examples/dataclasses_post_init_post_parse.py diff --git a/docs/examples/ex_debug.py b/docs/examples/devtools_main.py similarity index 100% rename from docs/examples/ex_debug.py rename to docs/examples/devtools_main.py diff --git a/docs/examples/export_copy.py b/docs/examples/exporting_models_copy.py similarity index 100% rename from docs/examples/export_copy.py rename to docs/examples/exporting_models_copy.py diff --git a/docs/examples/export_dict.py b/docs/examples/exporting_models_dict.py similarity index 100% rename from docs/examples/export_dict.py rename to docs/examples/exporting_models_dict.py diff --git a/docs/examples/advanced_exclude1.py b/docs/examples/exporting_models_exclude1.py similarity index 100% rename from docs/examples/advanced_exclude1.py rename to docs/examples/exporting_models_exclude1.py diff --git a/docs/examples/advanced_exclude2.py b/docs/examples/exporting_models_exclude2.py similarity index 100% rename from docs/examples/advanced_exclude2.py rename to docs/examples/exporting_models_exclude2.py diff --git a/docs/examples/export_iterate.py b/docs/examples/exporting_models_iterate.py similarity index 100% rename from docs/examples/export_iterate.py rename to docs/examples/exporting_models_iterate.py diff --git a/docs/examples/export_json.py b/docs/examples/exporting_models_json.py similarity index 100% rename from docs/examples/export_json.py rename to docs/examples/exporting_models_json.py diff --git a/docs/examples/json_orjson.py b/docs/examples/exporting_models_orjson.py similarity index 100% rename from docs/examples/json_orjson.py rename to docs/examples/exporting_models_orjson.py diff --git a/docs/examples/export_pickle.py b/docs/examples/exporting_models_pickle.py similarity index 100% rename from docs/examples/export_pickle.py rename to docs/examples/exporting_models_pickle.py diff --git a/docs/examples/json_ujson.py b/docs/examples/exporting_models_ujson.py similarity index 100% rename from docs/examples/json_ujson.py rename to docs/examples/exporting_models_ujson.py diff --git a/docs/examples/example2.py b/docs/examples/index_error.py similarity index 86% rename from docs/examples/example2.py rename to docs/examples/index_error.py index 591bba5..ffecf2e 100644 --- a/docs/examples/example2.py +++ b/docs/examples/index_error.py @@ -1,5 +1,5 @@ # output-json -from example1 import User +from index_main import User # ignore-above from pydantic import ValidationError diff --git a/docs/examples/example1.py b/docs/examples/index_main.py similarity index 100% rename from docs/examples/example1.py rename to docs/examples/index_main.py diff --git a/docs/examples/alias_generator_config.py b/docs/examples/model_config_alias_generator.py similarity index 100% rename from docs/examples/alias_generator_config.py rename to docs/examples/model_config_alias_generator.py diff --git a/docs/examples/alias_precedence.py b/docs/examples/model_config_alias_precedence.py similarity index 100% rename from docs/examples/alias_precedence.py rename to docs/examples/model_config_alias_precedence.py diff --git a/docs/examples/ex_dataclasses_config.py b/docs/examples/model_config_dataclass.py similarity index 100% rename from docs/examples/ex_dataclasses_config.py rename to docs/examples/model_config_dataclass.py diff --git a/docs/examples/config.py b/docs/examples/model_config_main.py similarity index 100% rename from docs/examples/config.py rename to docs/examples/model_config_main.py diff --git a/docs/examples/ex_abc.py b/docs/examples/models_abc.py similarity index 100% rename from docs/examples/ex_abc.py rename to docs/examples/models_abc.py diff --git a/docs/examples/ex_construct.py b/docs/examples/models_construct.py similarity index 100% rename from docs/examples/ex_construct.py rename to docs/examples/models_construct.py diff --git a/docs/examples/custom_root_field.py b/docs/examples/models_custom_root_field.py similarity index 100% rename from docs/examples/custom_root_field.py rename to docs/examples/models_custom_root_field.py diff --git a/docs/examples/data_conversion.py b/docs/examples/models_data_conversion.py similarity index 100% rename from docs/examples/data_conversion.py rename to docs/examples/models_data_conversion.py diff --git a/docs/examples/dynamic_model_creation.py b/docs/examples/models_dynamic_creation.py similarity index 100% rename from docs/examples/dynamic_model_creation.py rename to docs/examples/models_dynamic_creation.py diff --git a/docs/examples/dynamic_inheritance.py b/docs/examples/models_dynamic_inheritance.py similarity index 100% rename from docs/examples/dynamic_inheritance.py rename to docs/examples/models_dynamic_inheritance.py diff --git a/docs/examples/errors1.py b/docs/examples/models_errors1.py similarity index 100% rename from docs/examples/errors1.py rename to docs/examples/models_errors1.py diff --git a/docs/examples/errors2.py b/docs/examples/models_errors2.py similarity index 100% rename from docs/examples/errors2.py rename to docs/examples/models_errors2.py diff --git a/docs/examples/errors3.py b/docs/examples/models_errors3.py similarity index 100% rename from docs/examples/errors3.py rename to docs/examples/models_errors3.py diff --git a/docs/examples/field_order.py b/docs/examples/models_field_order.py similarity index 100% rename from docs/examples/field_order.py rename to docs/examples/models_field_order.py diff --git a/docs/examples/generics.py b/docs/examples/models_generics.py similarity index 100% rename from docs/examples/generics.py rename to docs/examples/models_generics.py diff --git a/docs/examples/generics-naming.py b/docs/examples/models_generics_naming.py similarity index 100% rename from docs/examples/generics-naming.py rename to docs/examples/models_generics_naming.py diff --git a/docs/examples/mutation.py b/docs/examples/models_mutation.py similarity index 100% rename from docs/examples/mutation.py rename to docs/examples/models_mutation.py diff --git a/docs/examples/orm_mode.py b/docs/examples/models_orm_mode.py similarity index 100% rename from docs/examples/orm_mode.py rename to docs/examples/models_orm_mode.py diff --git a/docs/examples/orm_mode_recursive.py b/docs/examples/models_orm_mode_recursive.py similarity index 100% rename from docs/examples/orm_mode_recursive.py rename to docs/examples/models_orm_mode_recursive.py diff --git a/docs/examples/parse.py b/docs/examples/models_parse.py similarity index 100% rename from docs/examples/parse.py rename to docs/examples/models_parse.py diff --git a/docs/examples/recursive.py b/docs/examples/models_recursive.py similarity index 100% rename from docs/examples/recursive.py rename to docs/examples/models_recursive.py diff --git a/docs/examples/mypy_example.py b/docs/examples/mypy_main.py similarity index 100% rename from docs/examples/mypy_example.py rename to docs/examples/mypy_main.py diff --git a/docs/examples/postponed_broken.py b/docs/examples/postponed_annotations_broken.py similarity index 100% rename from docs/examples/postponed_broken.py rename to docs/examples/postponed_annotations_broken.py diff --git a/docs/examples/forward_ref.py b/docs/examples/postponed_annotations_forward_ref.py similarity index 100% rename from docs/examples/forward_ref.py rename to docs/examples/postponed_annotations_forward_ref.py diff --git a/docs/examples/postponed_annotations.py b/docs/examples/postponed_annotations_main.py similarity index 100% rename from docs/examples/postponed_annotations.py rename to docs/examples/postponed_annotations_main.py diff --git a/docs/examples/self_referencing_annotations.py b/docs/examples/postponed_annotations_self_referencing_annotations.py similarity index 100% rename from docs/examples/self_referencing_annotations.py rename to docs/examples/postponed_annotations_self_referencing_annotations.py diff --git a/docs/examples/self_referencing_string.py b/docs/examples/postponed_annotations_self_referencing_string.py similarity index 100% rename from docs/examples/self_referencing_string.py rename to docs/examples/postponed_annotations_self_referencing_string.py diff --git a/docs/examples/postponed_works.py b/docs/examples/postponed_annotations_works.py similarity index 100% rename from docs/examples/postponed_works.py rename to docs/examples/postponed_annotations_works.py diff --git a/docs/examples/schema3.py b/docs/examples/schema_custom.py similarity index 100% rename from docs/examples/schema3.py rename to docs/examples/schema_custom.py diff --git a/docs/examples/schema1.py b/docs/examples/schema_main.py similarity index 100% rename from docs/examples/schema1.py rename to docs/examples/schema_main.py diff --git a/docs/examples/schema2.py b/docs/examples/schema_top_level.py similarity index 100% rename from docs/examples/schema2.py rename to docs/examples/schema_top_level.py diff --git a/docs/examples/unenforced_constraints.py b/docs/examples/schema_unenforced_constraints.py similarity index 100% rename from docs/examples/unenforced_constraints.py rename to docs/examples/schema_unenforced_constraints.py diff --git a/docs/examples/schema4.py b/docs/examples/schema_with_example.py similarity index 100% rename from docs/examples/schema4.py rename to docs/examples/schema_with_example.py diff --git a/docs/examples/settings.py b/docs/examples/settings_main.py similarity index 100% rename from docs/examples/settings.py rename to docs/examples/settings_main.py diff --git a/docs/examples/bare_type_type.py b/docs/examples/types_bare_type.py similarity index 100% rename from docs/examples/bare_type_type.py rename to docs/examples/types_bare_type.py diff --git a/docs/examples/boolean.py b/docs/examples/types_boolean.py similarity index 100% rename from docs/examples/boolean.py rename to docs/examples/types_boolean.py diff --git a/docs/examples/callable.py b/docs/examples/types_callable.py similarity index 100% rename from docs/examples/callable.py rename to docs/examples/types_callable.py diff --git a/docs/examples/choices.py b/docs/examples/types_choices.py similarity index 100% rename from docs/examples/choices.py rename to docs/examples/types_choices.py diff --git a/docs/examples/ex_color_type.py b/docs/examples/types_color.py similarity index 100% rename from docs/examples/ex_color_type.py rename to docs/examples/types_color.py diff --git a/docs/examples/constrained_types.py b/docs/examples/types_constrained.py similarity index 100% rename from docs/examples/constrained_types.py rename to docs/examples/types_constrained.py diff --git a/docs/examples/custom_data_types.py b/docs/examples/types_custom_type.py similarity index 100% rename from docs/examples/custom_data_types.py rename to docs/examples/types_custom_type.py diff --git a/docs/examples/datetime_example.py b/docs/examples/types_dt.py similarity index 100% rename from docs/examples/datetime_example.py rename to docs/examples/types_dt.py diff --git a/docs/examples/ex_typing.py b/docs/examples/types_iterables.py similarity index 100% rename from docs/examples/ex_typing.py rename to docs/examples/types_iterables.py diff --git a/docs/examples/ex_json_type.py b/docs/examples/types_json_type.py similarity index 100% rename from docs/examples/ex_json_type.py rename to docs/examples/types_json_type.py diff --git a/docs/examples/literal1.py b/docs/examples/types_literal1.py similarity index 100% rename from docs/examples/literal1.py rename to docs/examples/types_literal1.py diff --git a/docs/examples/literal2.py b/docs/examples/types_literal2.py similarity index 100% rename from docs/examples/literal2.py rename to docs/examples/types_literal2.py diff --git a/docs/examples/literal3.py b/docs/examples/types_literal3.py similarity index 100% rename from docs/examples/literal3.py rename to docs/examples/types_literal3.py diff --git a/docs/examples/payment_card_number.py b/docs/examples/types_payment_card_number.py similarity index 100% rename from docs/examples/payment_card_number.py rename to docs/examples/types_payment_card_number.py diff --git a/docs/examples/ex_secret_types.py b/docs/examples/types_secret_types.py similarity index 100% rename from docs/examples/ex_secret_types.py rename to docs/examples/types_secret_types.py diff --git a/docs/examples/strict_types.py b/docs/examples/types_strict.py similarity index 100% rename from docs/examples/strict_types.py rename to docs/examples/types_strict.py diff --git a/docs/examples/type_type.py b/docs/examples/types_type.py similarity index 100% rename from docs/examples/type_type.py rename to docs/examples/types_type.py diff --git a/docs/examples/union_type_correct.py b/docs/examples/types_union_correct.py similarity index 100% rename from docs/examples/union_type_correct.py rename to docs/examples/types_union_correct.py diff --git a/docs/examples/union_type_incorrect.py b/docs/examples/types_union_incorrect.py similarity index 100% rename from docs/examples/union_type_incorrect.py rename to docs/examples/types_union_incorrect.py diff --git a/docs/examples/url_properties.py b/docs/examples/types_url_properties.py similarity index 100% rename from docs/examples/url_properties.py rename to docs/examples/types_url_properties.py diff --git a/docs/examples/url_punycode.py b/docs/examples/types_url_punycode.py similarity index 100% rename from docs/examples/url_punycode.py rename to docs/examples/types_url_punycode.py diff --git a/docs/examples/urls.py b/docs/examples/types_urls.py similarity index 100% rename from docs/examples/urls.py rename to docs/examples/types_urls.py diff --git a/docs/index.md b/docs/index.md index 107cc61..2973fa7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -20,7 +20,7 @@ Define how data should be in pure, canonical python; validate it with *pydantic* ## Example ```py -{!.tmp_examples/example1.py!} +{!.tmp_examples/index_main.py!} ``` _(This script is complete, it should run "as is")_ @@ -37,11 +37,11 @@ What's going on here: If validation fails pydantic will raise an error with a breakdown of what was wrong: ```py -{!.tmp_examples/example2.py!} +{!.tmp_examples/index_error.py!} ``` outputs: ```json -{!.tmp_examples/example2.json!} +{!.tmp_examples/index_error.json!} ``` ## Rationale diff --git a/docs/mypy_plugin.md b/docs/mypy_plugin.md index 144dff5..1e17bef 100644 --- a/docs/mypy_plugin.md +++ b/docs/mypy_plugin.md @@ -5,7 +5,7 @@ features to mypy that improve its ability to type-check your code. For example, consider the following script: ```py -{!.tmp_examples/mypy_example.py!} +{!.tmp_examples/mypy_main.py!} ``` Without any special configuration, mypy catches one of the errors (see [here](usage/mypy.md) for usage instructions): diff --git a/docs/usage/dataclasses.md b/docs/usage/dataclasses.md index 1c3d76b..342bfa3 100644 --- a/docs/usage/dataclasses.md +++ b/docs/usage/dataclasses.md @@ -4,7 +4,7 @@ If you don't want to use pydantic's `BaseModel` you can instead get the same dat Dataclasses work in python 3.6 using the [dataclasses backport package](https://github.com/ericvsmith/dataclasses). ```py -{!.tmp_examples/ex_dataclasses.py!} +{!.tmp_examples/dataclasses_main.py!} ``` _(This script is complete, it should run "as is")_ @@ -36,7 +36,7 @@ For more information about combining validators with dataclasses, see Nested dataclasses are supported both in dataclasses and normal models. ```py -{!.tmp_examples/ex_nested_dataclasses.py!} +{!.tmp_examples/dataclasses_nested.py!} ``` _(This script is complete, it should run "as is")_ @@ -49,7 +49,7 @@ with the help of `__post_init_post_parse__`. This is not the same as `__post_ini code *before* validation. ```py -{!.tmp_examples/ex_post_init_post_parse.py!} +{!.tmp_examples/dataclasses_post_init_post_parse.py!} ``` _(This script is complete, it should run "as is")_ @@ -57,6 +57,6 @@ Since version **v1.0**, any fields annotated with `dataclasses.InitVar` are pass `__post_init_post_parse__`. ```py -{!.tmp_examples/ex_post_init_post_parse_initvars.py!} +{!.tmp_examples/dataclasses_initvars.py!} ``` _(This script is complete, it should run "as is")_ diff --git a/docs/usage/devtools.md b/docs/usage/devtools.md index 4801402..51af600 100644 --- a/docs/usage/devtools.md +++ b/docs/usage/devtools.md @@ -12,9 +12,9 @@ In particular `debug()` is useful when inspecting models: ```py -{!.tmp_examples/ex_debug.py!} +{!.tmp_examples/devtools_main.py!} ``` Will output in your terminal: -{!.tmp_examples/ex_debug.html!} +{!.tmp_examples/devtools_main.html!} diff --git a/docs/usage/exporting_models.md b/docs/usage/exporting_models.md index 22b41de..2fb8e1b 100644 --- a/docs/usage/exporting_models.md +++ b/docs/usage/exporting_models.md @@ -19,7 +19,7 @@ Arguments: Example: ```py -{!.tmp_examples/export_dict.py!} +{!.tmp_examples/exporting_models_dict.py!} ``` _(This script is complete, it should run "as is")_ @@ -32,7 +32,7 @@ returned, so sub-models will not be converted to dictionaries. Example: ```py -{!.tmp_examples/export_iterate.py!} +{!.tmp_examples/exporting_models_iterate.py!} ``` _(This script is complete, it should run "as is")_ @@ -50,7 +50,7 @@ Arguments: Example: ```py -{!.tmp_examples/export_copy.py!} +{!.tmp_examples/exporting_models_copy.py!} ``` _(This script is complete, it should run "as is")_ @@ -80,7 +80,7 @@ Arguments: Example: ```py -{!.tmp_examples/export_json.py!} +{!.tmp_examples/exporting_models_json.py!} ``` _(This script is complete, it should run "as is")_ @@ -95,7 +95,7 @@ and decoding. Using the same plumbing as `copy()`, *pydantic* models support efficient pickling and unpickling. ```py -{!.tmp_examples/export_pickle.py!} +{!.tmp_examples/exporting_models_pickle.py!} ``` _(This script is complete, it should run "as is")_ @@ -105,14 +105,14 @@ The `dict`, `json`, and `copy` methods support `include` and `exclude` arguments sets or dictionaries. This allows nested selection of which fields to export: ```py -{!.tmp_examples/advanced_exclude1.py!} +{!.tmp_examples/exporting_models_exclude1.py!} ``` The ellipsis (``...``) indicates that we want to exclude or include an entire key, just as if we included it in a set. Of course, the same can be done at any depth level: ```py -{!.tmp_examples/advanced_exclude2.py!} +{!.tmp_examples/exporting_models_exclude2.py!} ``` The same holds for the `json` and `copy` methods. @@ -124,7 +124,7 @@ To improve the performance of encoding and decoding JSON, alternative JSON imple `json_loads` and `json_dumps` properties of `Config`. ```py -{!.tmp_examples/json_ujson.py!} +{!.tmp_examples/exporting_models_ujson.py!} ``` _(This script is complete, it should run "as is")_ @@ -133,7 +133,7 @@ not accept a `default` fallback function argument. To do this, you may use anoth [orjson](https://github.com/ijl/orjson). ```py -{!.tmp_examples/json_orjson.py!} +{!.tmp_examples/exporting_models_orjson.py!} ``` _(This script is complete, it should run "as is")_ diff --git a/docs/usage/model_config.md b/docs/usage/model_config.md index 6fb55d7..d8f1e49 100644 --- a/docs/usage/model_config.md +++ b/docs/usage/model_config.md @@ -78,14 +78,14 @@ not be included in the model schemas. **Note**: this means that attributes on th : a `dict` used to customise the way types are encoded to JSON; see [JSON Serialisation](exporting_models.md#modeljson) ```py -{!.tmp_examples/config.py!} +{!.tmp_examples/model_config_main.py!} ``` _(This script is complete, it should run "as is")_ Similarly, if using the `@dataclass` decorator: ```py -{!.tmp_examples/ex_dataclasses_config.py!} +{!.tmp_examples/model_config_dataclass.py!} ``` _(This script is complete, it should run "as is")_ @@ -95,7 +95,7 @@ If data source field names do not match your code style (e. g. CamelCase fields) you can automatically generate aliases using `alias_generator`: ```py -{!.tmp_examples/alias_generator_config.py!} +{!.tmp_examples/model_config_alias_generator.py!} ``` _(This script is complete, it should run "as is")_ @@ -106,7 +106,7 @@ Aliases defined on the `Config` class of child models will take priority over an parent model: ```py -{!.tmp_examples/alias_precedence.py!} +{!.tmp_examples/model_config_alias_precedence.py!} ``` _(This script is complete, it should run "as is")_ diff --git a/docs/usage/models.md b/docs/usage/models.md index 34220a4..ad4c753 100644 --- a/docs/usage/models.md +++ b/docs/usage/models.md @@ -110,7 +110,7 @@ Models possess the following methods and attributes: More complex hierarchical data structures can be defined using models themselves as types in annotations. ```py -{!.tmp_examples/recursive.py!} +{!.tmp_examples/models_recursive.py!} ``` _(This script is complete, it should run "as is")_ @@ -128,7 +128,7 @@ To do this: The example here uses SQLAlchemy, but the same approach should work for any ORM. ```py -{!.tmp_examples/orm_mode.py!} +{!.tmp_examples/models_orm_mode.py!} ``` _(This script is complete, it should run "as is")_ @@ -137,7 +137,7 @@ ORM instances will be parsed with `from_orm` recursively as well as at the top l Here a vanilla class is used to demonstrate the principle, but any ORM class could be used instead. ```py -{!.tmp_examples/orm_mode_recursive.py!} +{!.tmp_examples/models_orm_mode_recursive.py!} ``` _(This script is complete, it should run "as is")_ @@ -191,7 +191,7 @@ Each error object contains: As a demonstration: ```py -{!.tmp_examples/errors1.py!} +{!.tmp_examples/models_errors1.py!} ``` _(This script is complete, it should run "as is". `json()` has `indent=2` set by default, but I've tweaked the JSON here and below to make it slightly more concise.)_ @@ -203,14 +203,14 @@ In your custom data types or validators you should use `ValueError`, `TypeError` See [validators](validators.md) for more details on use of the `@validator` decorator. ```py -{!.tmp_examples/errors2.py!} +{!.tmp_examples/models_errors2.py!} ``` _(This script is complete, it should run "as is")_ You can also define your own error classes, which can specify a custom error code, message template, and context: ```py -{!.tmp_examples/errors3.py!} +{!.tmp_examples/models_errors3.py!} ``` _(This script is complete, it should run "as is")_ @@ -226,7 +226,7 @@ _(This script is complete, it should run "as is")_ it is inferred from the file's extension. ```py -{!.tmp_examples/parse.py!} +{!.tmp_examples/models_parse.py!} ``` _(This script is complete, it should run "as is")_ @@ -250,7 +250,7 @@ as efficiently as possible (`construct()` is generally around 30x faster than cr ever use the `construct()` method with data which has already been validated, or you trust.** ```py -{!.tmp_examples/ex_construct.py!} +{!.tmp_examples/models_construct.py!} ``` _(This script is complete, it should run "as is")_ @@ -281,7 +281,7 @@ In order to declare a generic model, you perform the following steps: Here is an example using `GenericModel` to create an easily-reused HTTP response payload wrapper: ```py -{!.tmp_examples/generics.py!} +{!.tmp_examples/models_generics.py!} ``` _(This script is complete, it should run "as is")_ @@ -299,7 +299,7 @@ you would expect mypy to provide if you were to declare the type without using ` If the name of the concrete subclasses is important, you can also override the default behavior: ```py -{!.tmp_examples/generics-naming.py!} +{!.tmp_examples/models_generics_naming.py!} ``` _(This script is complete, it should run "as is")_ @@ -309,7 +309,7 @@ There are some occasions where the shape of a model is not known until runtime. the `create_model` method to allow models to be created on the fly. ```py -{!.tmp_examples/dynamic_model_creation.py!} +{!.tmp_examples/models_dynamic_creation.py!} ``` Here `StaticFoobarModel` and `DynamicFoobarModel` are identical. @@ -319,7 +319,7 @@ special key word arguments `__config__` and `__base__` can be used to customise extending a base model with extra fields. ```py -{!.tmp_examples/dynamic_inheritance.py!} +{!.tmp_examples/models_dynamic_inheritance.py!} ``` ## Custom Root Types @@ -332,7 +332,7 @@ The root value can be passed to model `__init__` via the `__root__` keyword argu the first and only argument to `parse_obj`. ```py -{!.tmp_examples/custom_root_field.py!} +{!.tmp_examples/models_custom_root_field.py!} ``` ## Faux Immutability @@ -345,7 +345,7 @@ values of instance attributes will raise errors. See [model config](model_config modify a so-called "immutable" object. ```py -{!.tmp_examples/mutation.py!} +{!.tmp_examples/models_mutation.py!} ``` Trying to change `a` caused an error, and `a` remains unchanged. However, the dict `b` is mutable, and the @@ -357,7 +357,7 @@ Pydantic models can be used alongside Python's [Abstract Base Classes](https://docs.python.org/3/library/abc.html) (ABCs). ```py -{!.tmp_examples/ex_abc.py!} +{!.tmp_examples/models_abc.py!} ``` _(This script is complete, it should run "as is")_ @@ -375,7 +375,7 @@ As of **v1.0** all fields with annotations (whether annotation-only or with a de all fields without an annotation. Within their respective groups, fields remain in the order they were defined. ```py -{!.tmp_examples/field_order.py!} +{!.tmp_examples/models_field_order.py!} ``` _(This script is complete, it should run "as is")_ @@ -413,7 +413,7 @@ and in some cases this may result in a loss of information. For example: ```py -{!.tmp_examples/data_conversion.py!} +{!.tmp_examples/models_data_conversion.py!} ``` _(This script is complete, it should run "as is")_ diff --git a/docs/usage/mypy.md b/docs/usage/mypy.md index c0fac17..cf77333 100644 --- a/docs/usage/mypy.md +++ b/docs/usage/mypy.md @@ -2,7 +2,7 @@ Pydantic works with [mypy](http://mypy-lang.org/) provided you use the annotatio required fields: ```py -{!.tmp_examples/mypy_example.py!} +{!.tmp_examples/mypy_main.py!} ``` You can run your code through mypy with: diff --git a/docs/usage/postponed_annotations.md b/docs/usage/postponed_annotations.md index 19b3edb..cc44588 100644 --- a/docs/usage/postponed_annotations.md +++ b/docs/usage/postponed_annotations.md @@ -5,7 +5,7 @@ Postponed annotations (as described in [PEP563](https://www.python.org/dev/peps/ "just work". ```py -{!.tmp_examples/postponed_annotations.py!} +{!.tmp_examples/postponed_annotations_main.py!} ``` _(This script is complete, it should run "as is")_ @@ -20,7 +20,7 @@ For example, this happens whenever a model references itself as a field type. When this happens, you'll need to call `update_forward_refs` after the model has been created before it can be used: ```py -{!.tmp_examples/forward_ref.py!} +{!.tmp_examples/postponed_annotations_forward_ref.py!} ``` _(This script is complete, it should run "as is")_ @@ -32,13 +32,13 @@ _(This script is complete, it should run "as is")_ For example, this works fine: ```py -{!.tmp_examples/postponed_works.py!} +{!.tmp_examples/postponed_annotations_works.py!} ``` While this will break: ```py -{!.tmp_examples/postponed_broken.py!} +{!.tmp_examples/postponed_annotations_broken.py!} ``` Resolving this is beyond the call for *pydantic*: either remove the future import or declare the types globally. @@ -52,7 +52,7 @@ with a friendly error message if you forget). Within the model, you can refer to the not-yet-constructed model using a string: ```py -{!.tmp_examples/self_referencing_string.py!} +{!.tmp_examples/postponed_annotations_self_referencing_string.py!} ``` _(This script is complete, it should run "as is")_ @@ -61,6 +61,6 @@ Since `python 3.7`, you can also refer it by its type, provided you import `anno and *pydantic* versions). ```py -{!.tmp_examples/self_referencing_annotations.py!} +{!.tmp_examples/postponed_annotations_self_referencing_annotations.py!} ``` _(This script is complete, it should run "as is")_ diff --git a/docs/usage/schema.md b/docs/usage/schema.md index 6aade57..c446615 100644 --- a/docs/usage/schema.md +++ b/docs/usage/schema.md @@ -1,14 +1,14 @@ *Pydantic* allows auto creation of JSON Schemas from models: ```py -{!.tmp_examples/schema1.py!} +{!.tmp_examples/schema_main.py!} ``` _(This script is complete, it should run "as is")_ Outputs: ```json -{!.tmp_examples/schema1.json!} +{!.tmp_examples/schema_main.json!} ``` The generated schemas are compliant with the specifications: @@ -78,7 +78,7 @@ constraint to appear in the schema, even though it's not being checked upon pars to `Field()` with the raw schema attribute name: ```py -{!.tmp_examples/unenforced_constraints.py!} +{!.tmp_examples/schema_unenforced_constraints.py!} ``` _(This script is complete, it should run "as is")_ @@ -102,14 +102,14 @@ You can also generate a top-level JSON Schema that only includes a list of model sub-models in its `definitions`: ```py -{!.tmp_examples/schema2.py!} +{!.tmp_examples/schema_top_level.py!} ``` _(This script is complete, it should run "as is")_ Outputs: ```json -{!.tmp_examples/schema2.json!} +{!.tmp_examples/schema_top_level.json!} ``` ## Schema customization @@ -120,14 +120,14 @@ You can customize the generated `$ref` JSON location: the definitions are always This is useful if you need to extend or modify the JSON Schema default definitions location. E.g. with OpenAPI: ```py -{!.tmp_examples/schema3.py!} +{!.tmp_examples/schema_custom.py!} ``` _(This script is complete, it should run "as is")_ Outputs: ```json -{!.tmp_examples/schema3.json!} +{!.tmp_examples/schema_custom.json!} ``` It's also possible to extend/override the generated JSON schema in a model. @@ -137,12 +137,12 @@ To do it, use the `Config` sub-class attribute `schema_extra`. For example, you could add `examples` to the JSON Schema: ```py -{!.tmp_examples/schema4.py!} +{!.tmp_examples/schema_with_example.py!} ``` _(This script is complete, it should run "as is")_ Outputs: ```json -{!.tmp_examples/schema4.json!} +{!.tmp_examples/schema_with_example.json!} ``` diff --git a/docs/usage/settings.md b/docs/usage/settings.md index 52afea5..b23188f 100644 --- a/docs/usage/settings.md +++ b/docs/usage/settings.md @@ -13,7 +13,7 @@ This makes it easy to: For example: ```py -{!.tmp_examples/settings.py!} +{!.tmp_examples/settings_main.py!} ``` _(This script is complete, it should run "as is")_ diff --git a/docs/usage/types.md b/docs/usage/types.md index adcca18..59f720f 100644 --- a/docs/usage/types.md +++ b/docs/usage/types.md @@ -150,7 +150,7 @@ with custom properties and validation. *pydantic* uses standard library `typing` types as defined in PEP 484 to define complex objects. ```py -{!.tmp_examples/ex_typing.py!} +{!.tmp_examples/types_iterables.py!} ``` _(This script is complete, it should run "as is")_ @@ -162,7 +162,7 @@ The `Union` type allows a model attribute to accept different types, e.g.: This script is complete, it should run "as is". However, it may not reflect the desired behavior; see below. ```py -{!.tmp_examples/union_type_incorrect.py!} +{!.tmp_examples/types_union_incorrect.py!} ``` However, as can be seen above, *pydantic* will attempt to 'match' any of the types defined under `Union` and will use @@ -175,7 +175,7 @@ followed by less specific types. In the above example, the `UUID` class should p classes to preclude the unexpected representation as such: ```py -{!.tmp_examples/union_type_correct.py!} +{!.tmp_examples/types_union_correct.py!} ``` _(This script is complete, it should run "as is")_ @@ -184,7 +184,7 @@ _(This script is complete, it should run "as is")_ *pydantic* uses python's standard `enum` classes to define choices. ```py -{!.tmp_examples/choices.py!} +{!.tmp_examples/types_choices.py!} ``` _(This script is complete, it should run "as is")_ @@ -229,7 +229,7 @@ types: * `[±]P[DD]DT[HH]H[MM]M[SS]S` (ISO 8601 format for timedelta) ```py -{!.tmp_examples/datetime_example.py!} +{!.tmp_examples/types_dt.py!} ``` ### Booleans @@ -255,7 +255,7 @@ A standard `bool` field will raise a `ValidationError` if the value is not one o Here is a script demonstrating some of these behaviors: ```py -{!.tmp_examples/boolean.py!} +{!.tmp_examples/types_boolean.py!} ``` _(This script is complete, it should run "as is")_ @@ -264,7 +264,7 @@ _(This script is complete, it should run "as is")_ Fields can also be of type `Callable`: ```py -{!.tmp_examples/callable.py!} +{!.tmp_examples/types_callable.py!} ``` _(This script is complete, it should run "as is")_ @@ -279,14 +279,14 @@ _(This script is complete, it should run "as is")_ that are subclasses of `T`. ```py -{!.tmp_examples/type_type.py!} +{!.tmp_examples/types_type.py!} ``` _(This script is complete, it should run "as is")_ You may also use `Type` to specify that any class is allowed. ```py -{!.tmp_examples/bare_type_type.py!} +{!.tmp_examples/types_bare_type.py!} ``` _(This script is complete, it should run "as is")_ @@ -309,7 +309,7 @@ _(This script is complete, it should run "as is")_ may accept only specific literal values: ```py -{!.tmp_examples/literal1.py!} +{!.tmp_examples/types_literal1.py!} ``` _(This script is complete, it should run "as is")_ @@ -317,14 +317,14 @@ One benefit of this field type is that it can be used to check for equality with without needing to declare custom validators: ```py -{!.tmp_examples/literal2.py!} +{!.tmp_examples/types_literal2.py!} ``` _(This script is complete, it should run "as is")_ With proper ordering in an annotated `Union`, you can use this to parse types of decreasing specificity: ```py -{!.tmp_examples/literal3.py!} +{!.tmp_examples/types_literal3.py!} ``` _(This script is complete, it should run "as is")_ @@ -470,7 +470,7 @@ The above types (which all inherit from `AnyUrl`) will attempt to give descripti provided: ```py -{!.tmp_examples/urls.py!} +{!.tmp_examples/types_urls.py!} ``` _(This script is complete, it should run "as is")_ @@ -503,7 +503,7 @@ the above types export the following properties: If further validation is required, these properties can be used by validators to enforce specific behaviour: ```py -{!.tmp_examples/url_properties.py!} +{!.tmp_examples/types_url_properties.py!} ``` _(This script is complete, it should run "as is")_ @@ -514,7 +514,7 @@ _(This script is complete, it should run "as is")_ [this article](https://www.xudongz.com/blog/2017/idn-phishing/) for a good description of why this is important): ```py -{!.tmp_examples/url_punycode.py!} +{!.tmp_examples/types_url_punycode.py!} ``` _(This script is complete, it should run "as is")_ @@ -551,7 +551,7 @@ You can use the `Color` data type for storing colors as per (e.g. `"hsl(270, 60%, 70%)"`, `"hsl(270, 60%, 70%, .5)"`) ```py -{!.tmp_examples/ex_color_type.py!} +{!.tmp_examples/types_color.py!} ``` _(This script is complete, it should run "as is")_ @@ -599,7 +599,7 @@ that you do not want to be visible in logging or tracebacks. The `SecretStr` and `SecretBytes` will be formatted as either `'**********'` or `''` on conversion to json. ```py -{!.tmp_examples/ex_secret_types.py!} +{!.tmp_examples/types_secret_types.py!} ``` _(This script is complete, it should run "as is")_ @@ -610,7 +610,7 @@ It can also optionally be used to parse the loaded object into another type base the type `Json` is parameterised with: ```py -{!.tmp_examples/ex_json_type.py!} +{!.tmp_examples/types_json_type.py!} ``` _(This script is complete, it should run "as is")_ @@ -620,7 +620,7 @@ The `PaymentCardNumber` type validates [payment cards](https://en.wikipedia.org/ (such as a debit or credit card). ```py -{!.tmp_examples/payment_card_number.py!} +{!.tmp_examples/types_payment_card_number.py!} ``` _(This script is complete, it should run "as is")_ @@ -643,7 +643,7 @@ The actual validation verifies the card number is: The value of numerous common types can be restricted using `con*` type functions: ```py -{!.tmp_examples/constrained_types.py!} +{!.tmp_examples/types_constrained.py!} ``` _(This script is complete, it should run "as is")_ @@ -664,7 +664,7 @@ The following caveats apply: - `StrictFloat` (and the `strict` option of `ConstrainedFloat`) will not accept `int`. ```py -{!.tmp_examples/strict_types.py!} +{!.tmp_examples/types_strict.py!} ``` _(This script is complete, it should run "as is")_ @@ -674,6 +674,6 @@ You can also define your own custom data types. The classmethod `__get_validator to get validators to parse and validate the input data. ```py -{!.tmp_examples/custom_data_types.py!} +{!.tmp_examples/types_custom_type.py!} ``` _(This script is complete, it should run "as is")_