Comments (2)
I believe I've come across the same issue, but using strict types;
from pydantic import TypeAdapter, StrictStr, StrictFloat, StrictInt, StrictBool
from typing import Union
AttributeType = Union[StrictStr, StrictFloat, StrictInt, StrictBool, None]
TypeAdapter(AttributeType).dump_json('string') # '"string"' ✅
TypeAdapter(AttributeType).dump_json(1.0) # '1.0' ✅
TypeAdapter(AttributeType).dump_json(1) # '1.0' ❌
TypeAdapter(AttributeType).dump_json(True) # '1.0' ❌
TypeAdapter(AttributeType).dump_json(None) # 'null' ✅
Seems to just be the StrictFloat type that isn't actually behaving strictly.
from pydantic.
Hey @mducar @henrybetts,
Thanks for reporting this. Definitely something to be improved. Adding to the union issues milestone!
from pydantic.
Related Issues (20)
- Json field display garbled characters when ensure_ascii=True HOT 4
- Union discriminator validation raises irrelevant errors HOT 1
- Pydantic generic models fail to generate schema with typing-extensions 4.12 TypeVar HOT 5
- Pydantic model fails to generate with annotated list of models using discriminated union and typing-extensions==4.12.0 HOT 8
- PositiveInt behavior differs between v1 and v2 HOT 1
- New model config option: `warn_on_extra` HOT 1
- Broken decimal parsing when using BeforeValidator HOT 7
- Reading pickled model with new schema does not initialise defaults HOT 1
- Allow for model discrimination without the creation of another BaseModel HOT 3
- ambiguous union discrimination when multiple models correspond to the input arguments HOT 1
- Random fails in field serialization HOT 4
- Validation issue with alias fields and init args HOT 9
- "in-congruent" format validation behavior when exported to jsonschema HOT 2
- Failed to create model with two generic parameters when Typevar.default is set HOT 1
- Discriminator on non-Union types HOT 1
- Write new feature pattern docs HOT 1
- `AnyUrl` requires host for validation but `.host` is typed `None | str` HOT 3
- Increase tests coverage for new pipeline API HOT 4
- `model_json_schema()` fails to include annotated third-party types: "Default value is not JSON serializable [non-serializable-default]" HOT 3
- Dynamically include/exclude fields from dumps HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pydantic.