@@ -59,10 +59,10 @@ def merged_as_strategies(
59
59
continue
60
60
s = merged ([inputs [g ] for g in group ])
61
61
if s is not None and s != FALSEY :
62
- validators = [make_validator (s ) for s in schemas ]
62
+ validators = [make_validator (s ). is_valid for s in schemas ]
63
63
strats .append (
64
64
from_schema (s , custom_formats = custom_formats ).filter (
65
- lambda obj : all (v . is_valid (obj ) for v in validators )
65
+ lambda obj : all (v (obj ) for v in validators )
66
66
)
67
67
)
68
68
combined .update (group )
@@ -257,7 +257,7 @@ def number_schema(schema: dict) -> st.SearchStrategy[float]:
257
257
exclude_min = exclude_min ,
258
258
exclude_max = exclude_max ,
259
259
# Filter out negative-zero as it does not exist in JSON
260
- ).filter (lambda n : n != 0 or math . copysign ( 1 , n ) == 1 )
260
+ ).map (lambda n : n if n != 0 else abs ( n ) )
261
261
262
262
263
263
def rfc3339 (name : str ) -> st .SearchStrategy [str ]:
@@ -575,18 +575,19 @@ def object_schema(
575
575
dep_schemas = {k : v for k , v in dependencies .items () if k not in dep_names }
576
576
del dependencies
577
577
578
+ valid_name = make_validator (names ).is_valid
579
+ known_optional_names : List [str ] = sorted (
580
+ set (filter (valid_name , set (dep_names ).union (dep_schemas , properties )))
581
+ - set (required )
582
+ )
578
583
name_strats = (
579
- st .sampled_from (sorted (dep_names ) + sorted (dep_schemas ) + sorted (properties ))
580
- if (dep_names or dep_schemas or properties )
581
- else st .nothing (),
582
584
from_schema (names , custom_formats = custom_formats )
583
585
if additional_allowed
584
586
else st .nothing (),
585
- st .one_of ([st .from_regex (p ) for p in sorted (patterns )]),
586
- )
587
- all_names_strategy = st .one_of ([s for s in name_strats if not s .is_empty ]).filter (
588
- make_validator (names ).is_valid
587
+ st .sampled_from (known_optional_names ) if known_optional_names else st .nothing (),
588
+ st .one_of ([st .from_regex (p ).filter (valid_name ) for p in sorted (patterns )]),
589
589
)
590
+ all_names_strategy = st .one_of ([s for s in name_strats if not s .is_empty ])
590
591
591
592
@st .composite # type: ignore
592
593
def from_object_schema (draw : Any ) -> Any :
0 commit comments