Skip to content

Conversation

samuelcolvin
Copy link
Member

@samuelcolvin samuelcolvin commented Jun 21, 2017

fix #45

In the end, I thought about this and decided whitelisting things which can be coerced to strings made more sense.

It shouldn't affect performance much as most string-like things will be strings and returned before this logic kicks in.

@codecov
Copy link

codecov bot commented Jun 21, 2017

Codecov Report

Merging #52 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff          @@
##           master    #52   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          10     10           
  Lines         694    704   +10     
  Branches      155    157    +2     
=====================================
+ Hits          694    704   +10

@nielskou
Copy link

Thank you for the fix. I appreciate it.

However, I still think that "strict by default" would be better. I would expect pydantic to check the types, instead of cleaning the data: If I pass my data to a model, and it doesn't raise a Validation error, I expect my data to be of the right types. I expected Pydantic to more like mypy: a typechecker. Mypy would not allow an int were a str is required.

But maybe I shouldn't complain: dict(Model(**my_data)) will have the right types.

@samuelcolvin
Copy link
Member Author

samuelcolvin commented Jun 21, 2017 via email

@samuelcolvin
Copy link
Member Author

oh, I see what you mean now. I'll add StrictStr now.

But I don't want to change the default as I think if as user submits {"telephone": 1234567} it shouldn't throw an error, but rather be processed the same as {"telephone": "1234567"}.

@samuelcolvin samuelcolvin merged commit 53ba356 into master Jun 21, 2017
@samuelcolvin samuelcolvin deleted the stricter-str branch June 21, 2017 17:00
@nielskou
Copy link

Nice work 👍

@Gr1N Gr1N mentioned this pull request May 2, 2018
@samuelcolvin samuelcolvin mentioned this pull request Oct 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional typecasting
2 participants