8000 rename string_schema -> str_schema · pydantic/pydantic-core@e3607eb · GitHub
[go: up one dir, main page]

Skip to content

Commit e3607eb

Browse files
committed
rename string_schema -> str_schema
1 parent 7d7ca9f commit e3607eb

File tree

10 files changed

+39
-39
lines changed

10 files changed

+39
-39
lines changed

pydantic_core/core_schema.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ class StringSchema(TypedDict, total=False):
345345
serialization: SerSchema
346346

347347

348-
def string_schema(
348+
def str_schema(
349349
*,
350350
pattern: str | None = None,
351351
max_length: int | None = None,
@@ -363,7 +363,7 @@ def string_schema(
363363
364364
```py
365365
from pydantic_core import SchemaValidator, core_schema
366-
schema = core_schema.string_schema(max_length=10, min_length=2)
366+
schema = core_schema.str_schema(max_length=10, min_length=2)
367367
v = SchemaValidator(schema)
368368
assert v.validate_python('hello') == 'hello'
369369
```
@@ -938,7 +938,7 @@ def tuple_positional_schema(
938938
939939
```py
940940
from pydantic_core import SchemaValidator, core_schema
941-
schema = core_schema.tuple_positional_schema(core_schema.int_schema(), core_schema.string_schema())
941+
schema = core_schema.tuple_positional_schema(core_schema.int_schema(), core_schema.str_schema())
942942
v = SchemaValidator(schema)
943943
assert v.validate_python((1, 'hello')) == (1, 'hello')
944944
```
@@ -1223,7 +1223,7 @@ def dict_schema(
12231223
```py
12241224
from pydantic_core import SchemaValidator, core_schema
12251225
schema = core_schema.dict_schema(
1226-
keys_schema=core_schema.string_schema(), values_schema=core_schema.int_schema()
1226+
keys_schema=core_schema.str_schema(), values_schema=core_schema.int_schema()
12271227
)
12281228
v = SchemaValidator(schema)
12291229
assert v.validate_python({'a': '1', 'b': 2}) == {'a': 1, 'b': 2}
@@ -1289,7 +1289,7 @@ def fn(v: Any, **kwargs) -> str:
12891289
assert 'hello' in v_str
12901290
return v_str + 'world'
12911291
1292-
schema = core_schema.function_before_schema(function=fn, schema=core_schema.string_schema())
1292+
schema = core_schema.function_before_schema(function=fn, schema=core_schema.str_schema())
12931293
v = SchemaValidator(schema)
12941294
assert v.validate_python(b"hello ") == "b'hello 'world"
12951295
```
@@ -1330,7 +1330,7 @@ def fn(v: str, **kwargs) -> str:
13301330
assert 'hello' in v
13311331
return v + 'world'
13321332
1333-
schema = core_schema.function_after_schema(schema=core_schema.string_schema(), function=fn)
1333+
schema = core_schema.function_after_schema(schema=core_schema.str_schema(), function=fn)
13341334
v = SchemaValidator(schema)
13351335
assert v.validate_python('hello ') == 'hello world'
13361336
```
@@ -1401,7 +1401,7 @@ def function_wrap_schema(
14011401
def fn(v: str, *, validator, **kwargs) -> str:
14021402
return validator(input_value=v) + 'world'
14031403
1404-
schema = core_schema.function_wrap_schema(function=fn, schema=core_schema.string_schema())
1404+
schema = core_schema.function_wrap_schema(function=fn, schema=core_schema.str_schema())
14051405
v = SchemaValidator(schema)
14061406
assert v.validate_python('hello ') == 'hello world'
14071407
```
@@ -1493,7 +1493,7 @@ def with_default_schema(
14931493
14941494
```py
14951495
from pydantic_core import SchemaValidator, core_schema
1496-
schema = core_schema.with_default_schema(core_schema.string_schema(), default='hello')
1496+
schema = core_schema.with_default_schema(core_schema.str_schema(), default='hello')
14971497
wrapper_schema = core_schema.typed_dict_schema(
14981498
{'a': core_schema.typed_dict_field(schema)}
14991499
)
@@ -1548,7 +1548,7 @@ def nullable_schema(
15481548
15491549
```py
15501550
from pydantic_core import SchemaValidator, core_schema
1551-
schema = core_schema.nullable_schema(core_schema.string_schema())
1551+
schema = core_schema.nullable_schema(core_schema.str_schema())
15521552
v = SchemaValidator(schema)
15531553
assert v.validate_python(None) is None
15541554
```
@@ -1595,7 +1595,7 @@ def union_schema(
15951595
15961596
```py
15971597
from pydantic_core import SchemaValidator, core_schema
1598-
schema = core_schema.union_schema(core_schema.string_schema(), core_schema.int_schema())
1598+
schema = core_schema.union_schema(core_schema.str_schema(), core_schema.int_schema())
15991599
v = SchemaValidator(schema)
16001600
assert v.validate_python('hello') == 'hello'
16011601
assert v.validate_python(1) == 1
@@ -1660,13 +1660,13 @@ def tagged_union_schema(
16601660
from pydantic_core import SchemaValidator, core_schema
16611661
apple_schema = core_schema.typed_dict_schema(
16621662
{
1663-
'foo': core_schema.typed_dict_field(core_schema.string_schema()),
1663+
'foo': core_schema.typed_dict_field(core_schema.str_schema()),
16641664
'bar': core_schema.typed_dict_field(core_schema.int_schema()),
16651665
}
16661666
)
16671667
banana_schema = core_schema.typed_dict_schema(
16681668
{
1669-
'foo': core_schema.typed_dict_field(core_schema.string_schema()),
1669+
'foo': core_schema.typed_dict_field(core_schema.str_schema()),
16701670
'spam': core_schema.typed_dict_field(core_schema.list_schema(items_schema=core_schema.int_schema())),
16711671
}
16721672
)
@@ -1729,7 +1729,7 @@ def fn(v: str, **kwargs) -> str:
17291729
return v + ' world'
17301730
17311731
fn_schema = core_schema.function_plain_schema(function=fn)
1732-
schema = core_schema.chain_schema(fn_schema, fn_schema, fn_schema, core_schema.string_schema())
1732+
schema = core_schema.chain_schema(fn_schema, fn_schema, fn_schema, core_schema.str_schema())
17331733
v = SchemaValidator(schema)
17341734
assert v.validate_python("hello") == 'hello world world world'
17351735
```
@@ -1873,7 +1873,7 @@ def typed_dict_schema(
18731873
```py
18741874
from pydantic_core import SchemaValidator, core_schema
18751875
wrapper_schema = core_schema.typed_dict_schema(
1876-
{'a': core_schema.typed_dict_field(core_schema.string_schema())}
1876+
{'a': core_schema.typed_dict_field(core_schema.str_schema())}
18771877
)
18781878
v = SchemaValidator(wrapper_schema)
18791879
assert v.validate_python({'a': 'hello'}) == {'a': 'hello'}
@@ -1948,7 +1948,7 @@ class MyModel:
19481948
cls=MyModel,
19491949
config=CoreConfig(str_max_length=5),
19501950
schema=core_schema.typed_dict_schema(
1951-
fields={'a': core_schema.typed_dict_field(core_schema.string_schema())},
1951+
fields={'a': core_schema.typed_dict_field(core_schema.str_schema())},
19521952
),
19531953
)
19541954
v = SchemaValidator(schema)
@@ -1998,7 +1998,7 @@ def arguments_parameter(
19981998
19991999
```py
20002000
from pydantic_core import SchemaValidator, core_schema
2001-
param = core_schema.arguments_parameter(name='a', schema=core_schema.string_schema(), mode='positional_only')
2001+
param = core_schema.arguments_parameter(name='a', schema=core_schema.str_schema(), mode='positional_only')
20022002
```
20032003
20042004
Args:
@@ -2035,7 +2035,7 @@ def arguments_schema(
20352035
20362036
```py
20372037
from pydantic_core import SchemaValidator, core_schema
2038-
param_a = core_schema.arguments_parameter(name='a', schema=core_schema.string_schema(), mode='positional_only')
2038+
param_a = core_schema.arguments_parameter(name='a', schema=core_schema.str_schema(), mode='positional_only')
20392039
param_b = core_schema.arguments_parameter(name='b', schema=core_schema.bool_schema(), mode='positional_only')
20402040
schema = core_schema.arguments_schema(param_a, param_b)
20412041
v = SchemaValidator(schema)
@@ -2087,14 +2087,14 @@ def call_schema(
20872087
20882088
```py
20892089
from pydantic_core import SchemaValidator, core_schema
2090-
param_a = core_schema.arguments_parameter(name='a', schema=core_schema.string_schema(), mode='positional_only')
2090+
param_a = core_schema.arguments_parameter(name='a', schema=core_schema.str_schema(), mode='positional_only')
20912091
param_b = core_schema.arguments_parameter(name='b', schema=core_schema.bool_schema(), mode='positional_only')
20922092
args_schema = core_schema.arguments_schema(param_a, param_b)
20932093
20942094
schema = core_schema.call_schema(
20952095
arguments=args_schema,
20962096
function=lambda a, b: a + str(not b),
2097-
return_schema=core_schema.string_schema(),
2097+
return_schema=core_schema.str_schema(),
20982098
)
20992099
v = SchemaValidator(schema)
21002100
assert v.validate_python((('hello', True))) == 'helloFalse'
@@ -2218,7 +2218,7 @@ def json_schema(
22182218
from pydantic_core import SchemaValidator, core_schema
22192219
dict_schema = core_schema.typed_dict_schema(
22202220
{
2221-
'field_a': core_schema.typed_dict_field(core_schema.string_schema()),
2221+
'field_a': core_schema.typed_dict_field(core_schema.str_schema()),
22222222
'field_b': core_schema.typed_dict_field(core_schema.bool_schema()),
22232223
}
22242224
)

tests/benchmarks/test_micro_benchmarks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class MyCoreModel:
255255

256256
@pytest.mark.benchmark(group='string')
257257
def test_core_string_lax(benchmark):
258-
validator = SchemaValidator(core_schema.string_schema())
258+
validator = SchemaValidator(core_schema.str_schema())
259259
input_str = 'Hello ' * 20
260260

261261
assert validator.validate_python(input_str) == input_str
@@ -265,7 +265,7 @@ def test_core_string_lax(benchmark):
265265

266266
@pytest.mark.benchmark(group='string')
267267
def test_core_string_strict(benchmark):
268-
validator = SchemaValidator(core_schema.string_schema(strict=True))
268+
validator = SchemaValidator(core_schema.str_schema(strict=True))
269269
input_str = 'Hello ' * 20
270270

271271
assert validator.validate_python(input_str) == input_str

tests/serializers/test_dict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def test_dict_str_int():
10-
v = SchemaSerializer(core_schema.dict_schema(core_schema.string_schema(), core_schema.int_schema()))
10+
v = SchemaSerializer(core_schema.dict_schema(core_schema.str_schema(), core_schema.int_schema()))
1111
assert v.to_python({'a': 1, 'b': 2, 'c': 3}) == {'a': 1, 'b': 2, 'c': 3}
1212
assert v.to_python({'a': 1, 'b': 2, 'c': 3}, mode='json') == {'a': 1, 'b': 2, 'c': 3}
1313
assert v.to_json({'a': 1, 'b': 2, 'c': 3}) == b'{"a":1,"b":2,"c":3}'
@@ -109,7 +109,7 @@ def test_filter_args(params):
109109
],
110110
)
111111
def test_filter_args_nested(params):
112-
s = SchemaSerializer(core_schema.dict_schema(core_schema.string_schema(), core_schema.list_schema()))
112+
s = SchemaSerializer(core_schema.dict_schema(core_schema.str_schema(), core_schema.list_schema()))
113113

114114
include, exclude, expected = params['include'], params['exclude'], params['expected']
115115
value = {'0': [0], '1': [0, 1], '2': [0, 1, 2], '3': [0, 1, 2, 3]}

tests/serializers/test_list_tuple.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_list_fallback():
4343

4444

4545
def test_list_str_fallback():
46-
v = SchemaSerializer(core_schema.list_schema(core_schema.string_schema()))
46+
v = SchemaSerializer(core_schema.list_schema(core_schema.str_schema()))
4747
with pytest.warns(UserWarning) as warning_info:
4848
assert v.to_json([1, 2, 3]) == b'[1,2,3]'
4949
assert [w.message.args[0] for w in warning_info.list] == [
@@ -324,7 +324,7 @@ def test_tuple_pos_dict_key():
324324
s = SchemaSerializer(
325325
core_schema.dict_schema(
326326
core_schema.tuple_positional_schema(
327-
core_schema.int_schema(), core_schema.string_schema(), extra_schema=core_schema.int_schema()
327+
core_schema.int_schema(), core_schema.str_schema(), extra_schema=core_schema.int_schema()
328328
),
329329
core_schema.int_schema(),
330330
)

tests/serializers/test_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_dataclass():
6363
schema = core_schema.call_schema(
6464
core_schema.arguments_schema(
6565
core_schema.arguments_parameter('foo', core_schema.int_schema()),
66-
core_schema.arguments_parameter('bar', core_schema.string_schema()),
66+
core_schema.arguments_parameter('bar', core_schema.str_schema()),
6767
core_schema.arguments_parameter('spam', core_schema.bytes_schema(), mode='keyword_only'),
6868
),
6969
DataClass,
@@ -73,7 +73,7 @@ def test_dataclass():
7373
'schema': core_schema.typed_dict_schema(
7474
{
7575
'foo': core_schema.typed_dict_field(core_schema.int_schema()),
76-
'bar': core_schema.typed_dict_field(core_schema.string_schema()),
76+
'bar': core_schema.typed_dict_field(core_schema.str_schema()),
7777
'spam': core_schema.typed_dict_field(core_schema.bytes_schema()),
7878
}
7979
),

tests/serializers/test_other.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def test_chain():
7-
s = SchemaSerializer(core_schema.chain_schema(core_schema.string_schema(), core_schema.int_schema()))
7+
s = SchemaSerializer(core_schema.chain_schema(core_schema.str_schema(), core_schema.int_schema()))
88

99
# insert_assert(plain_repr(s))
1010
assert plain_repr(s) == 'SchemaSerializer(serializer=Int(IntSerializer),slots=[])'

tests/serializers/test_string.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def test_str():
11-
v = SchemaSerializer(core_schema.string_schema())
11+
v = SchemaSerializer(core_schema.str_schema())
1212
assert v.to_python('foobar') == 'foobar'
1313
assert v.to_python('emoji 💩') == 'emoji 💩'
1414
assert v.to_json('foobar') == b'"foobar"'
@@ -25,7 +25,7 @@ def test_str():
2525

2626

2727
def test_str_fallback():
28-
s = SchemaSerializer(core_schema.string_schema())
28+
s = SchemaSerializer(core_schema.str_schema())
2929
assert s.to_python(None) is None
3030
assert s.to_python(None, mode='json') is None
3131
assert s.to_json(None) == b'null'
@@ -38,7 +38,7 @@ def test_str_fallback():
3838

3939

4040
def test_str_no_warnings():
41-
s = SchemaSerializer(core_schema.string_schema())
41+
s = SchemaSerializer(core_schema.str_schema())
4242
assert s.to_python(123, warnings=False) == 123
4343
assert s.to_python(123, mode='json', warnings=False) == 123
4444
assert s.to_json(123, warnings=False) == b'123'

tests/test_schema_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def args(*args, **kwargs):
4242
(core_schema.int_schema, args(multiple_of=5, gt=10, lt=20), {'type': 'int', 'multiple_of': 5, 'gt': 10, 'lt': 20}),
4343
(core_schema.float_schema, args(), {'type': 'float'}),
4444
(core_schema.float_schema, args(multiple_of=5, gt=1.2), {'type': 'float', 'multiple_of': 5, 'gt': 1.2}),
45-
(core_schema.string_schema, args(), {'type': 'str'}),
46-
(core_schema.string_schema, args(min_length=5, max_length=10), {'type': 'str', 'min_length': 5, 'max_length': 10}),
45+
(core_schema.str_schema, args(), {'type': 'str'}),
46+
(core_schema.str_schema, args(min_length=5, max_length=10), {'type': 'str', 'min_length': 5, 'max_length': 10}),
4747
(core_schema.bytes_schema, args(), {'type': 'bytes'}),
4848
(core_schema.bytes_schema, args(min_length=5, ref='xx'), {'type': 'bytes', 'min_length': 5, 'ref': 'xx'}),
4949
(core_schema.date_schema, args(), {'type': 'date'}),

tests/validators/test_lax_or_strict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def test_lax_or_strict():
7-
v = SchemaValidator(core_schema.lax_or_strict_schema(core_schema.string_schema(), core_schema.int_schema()))
7+
v = SchemaValidator(core_schema.lax_or_strict_schema(core_schema.str_schema(), core_schema.int_schema()))
88
# validator is default - lax so with no runtime arg, we're in lax mode, and we use the string validator
99
assert v.validate_python('aaa') == 'aaa'
1010
# the strict validator is itself lax
@@ -23,7 +23,7 @@ def test_lax_or_strict():
2323

2424
def test_lax_or_strict_default_strict():
2525
v = SchemaValidator(
26-
core_schema.lax_or_strict_schema(core_schema.string_schema(), core_schema.int_schema(), strict=True)
26+
core_schema.lax_or_strict_schema(core_schema.str_schema(), core_schema.int_schema(), strict=True)
2727
)
2828
assert v.validate_python('aaa', strict=False) == 'aaa'
2929
assert v.validate_python(b'aaa', strict=False) == 'aaa'

tests/validators/test_string.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_regex_error():
184184

185185

186186
def test_default_validator():
187-
v = SchemaValidator(core_schema.string_schema(strict=True, to_lower=False), {'str_strip_whitespace': False})
187+
v = SchemaValidator(core_schema.str_schema(strict=True, to_lower=False), {'str_strip_whitespace': False})
188188
assert plain_repr(v) == 'SchemaValidator(name="str",validator=Str(StrValidator{strict:true}),slots=[])'
189189

190190

@@ -201,7 +201,7 @@ class FruitEnum(str, Enum):
201201

202202
@pytest.mark.parametrize('kwargs', [{}, {'to_lower': True}], ids=repr)
203203
def test_strict_subclass(FruitEnum, kwargs):
204-
v = SchemaValidator(core_schema.string_schema(strict=True, **kwargs))
204+
v = SchemaValidator(core_schema.str_schema(strict=True, **kwargs))
205205
assert v.validate_python('foobar') == 'foobar'
206206
with pytest.raises(ValidationError, match='type=string_type,'):
207207
v.validate_python(b'foobar')
@@ -220,7 +220,7 @@ def test_strict_subclass(FruitEnum, kwargs):
220220

221221
@pytest.mark.parametrize('kwargs', [{}, {'to_lower': True}], ids=repr)
222222
def test_lax_subclass(FruitEnum, kwargs):
223-
v = SchemaValidator(core_schema.string_schema(**kwargs))
223+
v = SchemaValidator(core_schema.str_schema(**kwargs))
224224
assert v.validate_python('foobar') == 'foobar'
225225
assert v.validate_python(b'foobar') == 'foobar'
226226
p = v.validate_python(FruitEnum.pear)

0 commit comments

Comments
 (0)
0