From 0299082d0cc6ff66271a9522ce7e4ae4217dd505 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Mon, 5 Jun 2023 19:02:18 +0330 Subject: [PATCH 1/2] Add more types to conversion table --- docs/plugins/conversion_table.py | 727 ++++++++++++++++++++++++++++++- 1 file changed, 705 insertions(+), 22 deletions(-) diff --git a/docs/plugins/conversion_table.py b/docs/plugins/conversion_table.py index c450085e545..4193ede3659 100644 --- a/docs/plugins/conversion_table.py +++ b/docs/plugins/conversion_table.py @@ -1,34 +1,21 @@ from __future__ import annotations as _annotations +import collections +import typing +from collections import deque from dataclasses import dataclass from datetime import date, datetime, time, timedelta from decimal import Decimal -from typing import Any, Literal, Mapping +from enum import Enum, IntEnum +from pathlib import Path +from typing import Any, Iterable, Literal, Mapping, Pattern, Sequence, Type +from uuid import UUID from pydantic_core import CoreSchema, core_schema from typing_extensions import TypedDict -# TODO: List of missing types -# deque -# typing.Any -# typing.NamedTuple -# collections.namedtuple -# typing.Sequence -# typing.Iterable -# typing.Type -# typing.Pattern -# ipaddress.IPv4Address -# ipaddress.IPv4Interface -# ipaddress.IPv4Network -# ipaddress.IPv6Address -# ipaddress.IPv6Interface -# ipaddress.IPv6Network -# enum.Enum -# enum.IntEnum -# decimal.Decimal -# pathlib.Path -# uuid.UUID -# ByteSize +from pydantic import ByteSize +from pydantic.networks import IPv4Address, IPv4Interface, IPv4Network, IPv6Address, IPv6Interface, IPv6Network @dataclass @@ -820,4 +807,700 @@ class Row: condition='Never valid.', core_schemas=[core_schema.CallableSchema], ), + Row( + deque, + deque, + 'Strict', + 'Python', + core_schemas=[core_schema.WrapValidatorFunctionSchema], + ), + Row( + deque, + 'Array', + 'Strict', + 'Json', + core_schemas=[core_schema.WrapValidatorFunctionSchema], + ), + Row( + deque, + list, + 'Lax', + 'Python', + core_schemas=[core_schema.ChainSchema], + ), + Row( + deque, + tuple, + 'Lax', + 'Python', + core_schemas=[core_schema.ChainSchema], + ), + Row( + deque, + set, + 'Lax', + 'Python', + core_schemas=[core_schema.ChainSchema], + ), + Row( + deque, + frozenset, + 'Lax', + 'Python', + core_schemas=[core_schema.ChainSchema], + ), + Row( + Any, + Any, + 'Strict', + 'Python & JSON', + core_schemas=[core_schema.AnySchema], + ), + Row( + typing.NamedTuple, + typing.NamedTuple, + 'Strict', + 'Python', + core_schemas=[core_schema.CallSchema], + ), + Row( + typing.NamedTuple, + 'Array', + 'Strict', + 'JSON', + core_schemas=[core_schema.CallSchema], + ), + Row( + typing.NamedTuple, + collections.namedtuple, + 'Strict', + 'Python', + core_schemas=[core_schema.CallSchema], + ), + Row( + typing.NamedTuple, + tuple, + 'Strict', + 'Python', + core_schemas=[core_schema.CallSchema], + ), + Row( + typing.NamedTuple, + list, + 'Strict', + 'Python', + core_schemas=[core_schema.CallSchema], + ), + Row( + typing.NamedTuple, + dict, + 'Strict', + 'Python', + core_schemas=[core_schema.CallSchema], + ), + Row( + collections.namedtuple, + collections.namedtuple, + 'Strict', + 'Python', + core_schemas=[core_schema.CallSchema], + ), + Row( + collections.namedtuple, + 'Array', + 'Strict', + 'JSON', + core_schemas=[core_schema.CallSchema], + ), + Row( + collections.namedtuple, + typing.NamedTuple, + 'Strict', + 'Python', + core_schemas=[core_schema.CallSchema], + ), + Row( + collections.namedtuple, + tuple, + 'Strict', + 'Python', + core_schemas=[core_schema.CallSchema], + ), + Row( + collections.namedtuple, + list, + 'Strict', + 'Python', + core_schemas=[core_schema.CallSchema], + ), + Row( + collections.namedtuple, + dict, + 'Strict', + 'Python', + core_schemas=[core_schema.CallSchema], + ), + Row( + Sequence, + list, + 'Strict', + 'Python', + core_schemas=[core_schema.ChainSchema], + ), + Row( + Sequence, + 'Array', + 'Strict', + 'JSON', + core_schemas=[core_schema.ChainSchema], + ), + Row( + Sequence, + tuple, + 'Lax', + 'Python', + core_schemas=[core_schema.ChainSchema], + ), + Row( + Sequence, + deque, + 'Lax', + 'Python', + core_schemas=[core_schema.ChainSchema], + ), + Row( + Iterable, + list, + 'Strict', + 'Python', + core_schemas=[core_schema.GeneratorSchema], + ), + Row( + Iterable, + 'Array', + 'Strict', + 'JSON', + core_schemas=[core_schema.GeneratorSchema], + ), + Row( + Iterable, + tuple, + 'Strict', + 'Python', + core_schemas=[core_schema.GeneratorSchema], + ), + Row( + Iterable, + set, + 'Strict', + 'Python', + core_schemas=[core_schema.GeneratorSchema], + ), + Row( + Iterable, + frozenset, + 'Strict', + 'Python', + core_schemas=[core_schema.GeneratorSchema], + ), + Row( + Iterable, + deque, + 'Strict', + 'Python', + core_schemas=[core_schema.GeneratorSchema], + ), + Row( + Type, + Type, + 'Strict', + 'Python', + core_schemas=[core_schema.IsSubclassSchema], + ), + Row( + Pattern, + str, + 'Strict', + 'Python & JSON', + condition='Input should be a valid pattern.', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + Pattern, + bytes, + 'Strict', + 'Python', + condition='Input should be a valid pattern.', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv4Address, + IPv4Address, + 'Strict', + 'Python', + core_schemas=[core_schema.IsInstanceSchema], + ), + Row( + IPv4Address, + IPv4Interface, + 'Strict', + 'Python', + core_schemas=[core_schema.IsInstanceSchema], + ), + Row( + IPv4Address, + str, + 'Strict', + 'JSON', + core_schemas=[core_schema.AfterValidatorFunctionSchema], + ), + Row( + IPv4Address, + str, + 'Lax', + 'Python & JSON', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv4Address, + bytes, + 'Lax', + 'Python', + valid_examples=[b'\x00\x00\x00\x00'], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv4Address, + int, + 'Lax', + 'Python', + condition='integer representing the IP network, should be less than `2**32`', + valid_examples=[168_430_090], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv4Interface, + IPv4Interface, + 'Strict', + 'Python', + core_schemas=[core_schema.IsInstanceSchema], + ), + Row( + IPv4Interface, + str, + 'Strict', + 'JSON', + core_schemas=[core_schema.AfterValidatorFunctionSchema], + ), + Row( + IPv4Interface, + IPv4Address, + 'Lax', + 'Python & JSON', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv4Interface, + str, + 'Lax', + 'Python & JSON', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv4Interface, + bytes, + 'Lax', + 'Python', + valid_examples=[b'\xff\xff\xff\xff'], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv4Interface, + tuple, + 'Lax', + 'Python', + valid_examples=[('192.168.0.1', '24')], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv4Interface, + int, + 'Lax', + 'Python', + condition='integer representing the IP network, should be less than `2**32`', + valid_examples=[168_430_090], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv4Network, + IPv4Network, + 'Strict', + 'Python', + core_schemas=[core_schema.IsInstanceSchema], + ), + Row( + IPv4Network, + str, + 'Strict', + 'JSON', + core_schemas=[core_schema.AfterValidatorFunctionSchema], + ), + Row( + IPv4Network, + IPv4Address, + 'Lax', + 'Python & JSON', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv4Network, + IPv4Interface, + 'Lax', + 'Python & JSON', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv4Network, + str, + 'Lax', + 'Python & JSON', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv4Network, + bytes, + 'Lax', + 'Python', + valid_examples=[b'\xff\xff\xff\xff'], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv4Network, + int, + 'Lax', + 'Python', + condition='integer representing the IP network, should be less than `2**32`', + valid_examples=[168_430_090], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv6Address, + IPv6Address, + 'Strict', + 'Python', + core_schemas=[core_schema.IsInstanceSchema], + ), + Row( + IPv6Address, + IPv6Interface, + 'Strict', + 'Python', + core_schemas=[core_schema.IsInstanceSchema], + ), + Row( + IPv6Address, + str, + 'Strict', + 'JSON', + core_schemas=[core_schema.AfterValidatorFunctionSchema], + ), + Row( + IPv6Address, + str, + 'Lax', + 'Python & JSON', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv6Address, + bytes, + 'Lax', + 'Python', + valid_examples=[b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01'], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv6Address, + int, + 'Lax', + 'Python', + condition='integer representing the IP network, should be less than `2**32`', + valid_examples=[340_282_366_920_938_463_463_374_607_431_768_211_455], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv6Interface, + IPv6Interface, + 'Strict', + 'Python', + core_schemas=[core_schema.IsInstanceSchema], + ), + Row( + IPv6Interface, + str, + 'Strict', + 'JSON', + core_schemas=[core_schema.AfterValidatorFunctionSchema], + ), + Row( + IPv6Interface, + IPv6Address, + 'Lax', + 'Python & JSON', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv6Interface, + str, + 'Lax', + 'Python & JSON', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv6Interface, + bytes, + 'Lax', + 'Python', + valid_examples=[b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01'], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv6Interface, + tuple, + 'Lax', + 'Python', + valid_examples=[('2001:db00::1', '120')], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv6Interface, + int, + 'Lax', + 'Python', + condition='integer representing the IP network, should be less than `2**32`', + valid_examples=[340_282_366_920_938_463_463_374_607_431_768_211_455], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv6Network, + IPv6Network, + 'Strict', + 'Python', + core_schemas=[core_schema.IsInstanceSchema], + ), + Row( + IPv6Network, + str, + 'Strict', + 'JSON', + core_schemas=[core_schema.AfterValidatorFunctionSchema], + ), + Row( + IPv6Network, + IPv6Address, + 'Lax', + 'Python & JSON', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv6Network, + IPv6Interface, + 'Lax', + 'Python & JSON', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv6Network, + str, + 'Lax', + 'Python & JSON', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv6Network, + bytes, + 'Lax', + 'Python', + valid_examples=[b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01'], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IPv6Network, + int, + 'Lax', + 'Python', + condition='integer representing the IP network, should be less than `2**32`', + valid_examples=[340_282_366_920_938_463_463_374_607_431_768_211_455], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + Enum, + Enum, + 'Strict', + 'Python', + core_schemas=[core_schema.IsInstanceSchema], + ), + Row( + Enum, + Any, + 'Strict', + 'JSON', + condition='Input value should be convertible to enum values.', + core_schemas=[core_schema.PlainValidatorFunctionSchema()], + ), + Row( + Enum, + Any, + 'Lax', + 'Python', + condition='Input value should be convertible to enum values.', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + IntEnum, + IntEnum, + 'Strict', + 'Python', + core_schemas=[core_schema.IsInstanceSchema], + ), + Row( + IntEnum, + Any, + 'Strict', + 'JSON', + condition='Input value should be convertible to enum values.', + core_schemas=[core_schema.PlainValidatorFunctionSchema()], + ), + Row( + IntEnum, + Any, + 'Lax', + 'Python', + condition='Input value should be convertible to enum values.', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + Decimal, + Decimal, + 'Strict', + 'Python', + core_schemas=[core_schema.CustomErrorSchema], + ), + Row( + Decimal, + int, + 'Strict', + 'JSON', + core_schemas=[core_schema.CustomErrorSchema], + ), + Row( + Decimal, + str, + 'Strict', + 'JSON', + core_schemas=[core_schema.CustomErrorSchema], + ), + Row( + Decimal, + float, + 'Strict', + 'JSON', + core_schemas=[core_schema.CustomErrorSchema], + ), + Row( + Decimal, + int, + 'Lax', + 'Python & JSON', + core_schemas=[core_schema.AfterValidatorFunctionSchema], + ), + Row( + Decimal, + str, + 'Lax', + 'Python & JSON', + condition='Must match `[0-9]+(\\.[0-9]+)?`.', + valid_examples=['3.141'], + invalid_examples=['test'], + core_schemas=[core_schema.AfterValidatorFunctionSchema], + ), + Row( + Decimal, + float, + 'Lax', + 'Python & JSON', + core_schemas=[core_schema.AfterValidatorFunctionSchema], + ), + Row( + Path, + Path, + 'Strict', + 'Python', + core_schemas=[core_schema.IsInstanceSchema], + ), + Row( + Path, + str, + 'Strict', + 'JSON', + core_schemas=[core_schema.AfterValidatorFunctionSchema], + ), + Row( + Path, + str, + 'Lax', + 'Python', + core_schemas=[core_schema.AfterValidatorFunctionSchema], + ), + Row( + UUID, + UUID, + 'Strict', + 'Python', + core_schemas=[core_schema.IsInstanceSchema], + ), + Row( + UUID, + str, + 'Strict', + 'JSON', + core_schemas=[core_schema.AfterValidatorFunctionSchema], + ), + Row( + UUID, + str, + 'Lax', + 'Python', + valid_examples=['{12345678-1234-5678-1234-567812345678}'], + core_schemas=[core_schema.AfterValidatorFunctionSchema], + ), + Row( + ByteSize, + str, + 'Strict', + 'Python & JSON', + valid_examples=['1.2', '1.5 KB', '6.2EiB'], + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + ByteSize, + int, + 'Strict', + 'Python & JSON', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + ByteSize, + float, + 'Strict', + 'Python & JSON', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), + Row( + ByteSize, + Decimal, + 'Strict', + 'Python', + core_schemas=[core_schema.PlainValidatorFunctionSchema], + ), ] From b6ba899ab61cceeb3d1c5b6d4c5bf28017a11a34 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Tue, 6 Jun 2023 00:02:51 +0330 Subject: [PATCH 2/2] Fix network types condition --- docs/plugins/conversion_table.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/plugins/conversion_table.py b/docs/plugins/conversion_table.py index 4193ede3659..5ce8e100f7c 100644 --- a/docs/plugins/conversion_table.py +++ b/docs/plugins/conversion_table.py @@ -1074,7 +1074,7 @@ class Row: int, 'Lax', 'Python', - condition='integer representing the IP network, should be less than `2**32`', + condition='integer representing the IP address, should be less than `2**32`', valid_examples=[168_430_090], core_schemas=[core_schema.PlainValidatorFunctionSchema], ), @@ -1127,7 +1127,7 @@ class Row: int, 'Lax', 'Python', - condition='integer representing the IP network, should be less than `2**32`', + condition='integer representing the IP address, should be less than `2**32`', valid_examples=[168_430_090], core_schemas=[core_schema.PlainValidatorFunctionSchema], ), @@ -1224,7 +1224,7 @@ class Row: int, 'Lax', 'Python', - condition='integer representing the IP network, should be less than `2**32`', + condition='integer representing the IP address, should be less than `2**128`', valid_examples=[340_282_366_920_938_463_463_374_607_431_768_211_455], core_schemas=[core_schema.PlainValidatorFunctionSchema], ), @@ -1277,7 +1277,7 @@ class Row: int, 'Lax', 'Python', - condition='integer representing the IP network, should be less than `2**32`', + condition='integer representing the IP address, should be less than `2**128`', valid_examples=[340_282_366_920_938_463_463_374_607_431_768_211_455], core_schemas=[core_schema.PlainValidatorFunctionSchema], ), @@ -1329,7 +1329,7 @@ class Row: int, 'Lax', 'Python', - condition='integer representing the IP network, should be less than `2**32`', + condition='integer representing the IP address, should be less than `2**128`', valid_examples=[340_282_366_920_938_463_463_374_607_431_768_211_455], core_schemas=[core_schema.PlainValidatorFunctionSchema], ),