From 1ea90211abff29d934785c21faf4579334ab2d09 Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Mon, 2 Dec 2024 08:55:12 -0600 Subject: [PATCH] simplify changes from main --- lexicons/tools.ozone.moderation.queryEvents.json | 2 +- packages/atproto_client/models/string_formats.py | 15 +++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/lexicons/tools.ozone.moderation.queryEvents.json b/lexicons/tools.ozone.moderation.queryEvents.json index 9e89a948..73c9b084 100644 --- a/lexicons/tools.ozone.moderation.queryEvents.json +++ b/lexicons/tools.ozone.moderation.queryEvents.json @@ -132,4 +132,4 @@ } } } -} +} \ No newline at end of file diff --git a/packages/atproto_client/models/string_formats.py b/packages/atproto_client/models/string_formats.py index d32707a1..b0598d5e 100644 --- a/packages/atproto_client/models/string_formats.py +++ b/packages/atproto_client/models/string_formats.py @@ -1,13 +1,12 @@ import re from datetime import datetime -from inspect import signature -from typing import Mapping, Set, Union, cast +from typing import Callable, Mapping, Set, Union, cast from urllib.parse import urlparse from atproto_core.nsid import validate_nsid as atproto_core_validate_nsid from pydantic import BeforeValidator, Field, ValidationInfo from pydantic_core import core_schema -from typing_extensions import Annotated, Literal, TypeAlias +from typing_extensions import Annotated, Literal _OPT_IN_KEY: Literal['strict_string_format'] = 'strict_string_format' @@ -51,21 +50,13 @@ r')?$' ) -WithOrWithoutInfoValidator: TypeAlias = Union[ - core_schema.WithInfoValidatorFunction, core_schema.NoInfoValidatorFunction -] - -def only_validate_if_strict(validate_fn: WithOrWithoutInfoValidator) -> WithOrWithoutInfoValidator: +def only_validate_if_strict(validate_fn: Callable[..., str]) -> Callable[..., str]: """Skip pydantic validation if not opting into strict validation via context.""" - params = list(signature(validate_fn).parameters.values()) - validator_wants_info = len(params) > 1 and params[1].annotation is ValidationInfo def wrapper(v: str, info: ValidationInfo) -> str: """Could likely be generalized to support arbitrary signatures.""" if info and isinstance(info.context, Mapping) and info.context.get(_OPT_IN_KEY, False): - if validator_wants_info: - return cast(core_schema.WithInfoValidatorFunction, validate_fn)(v, info) return cast(core_schema.NoInfoValidatorFunction, validate_fn)(v) return v