Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stricter str validation #52

Merged
merged 4 commits into from Jun 21, 2017
Merged

stricter str validation #52

merged 4 commits into from Jun 21, 2017

Conversation

@samuelcolvin
Copy link
Owner

@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 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

Loading

@Zweedeend
Copy link

@Zweedeend Zweedeend commented Jun 21, 2017

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.

Loading

@samuelcolvin
Copy link
Owner Author

@samuelcolvin samuelcolvin commented Jun 21, 2017

Loading

@samuelcolvin
Copy link
Owner Author

@samuelcolvin samuelcolvin commented Jun 21, 2017

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"}.

Loading

@samuelcolvin samuelcolvin merged commit 53ba356 into master Jun 21, 2017
4 checks passed
Loading
@samuelcolvin samuelcolvin deleted the stricter-str branch Jun 21, 2017
@Zweedeend
Copy link

@Zweedeend Zweedeend commented Jun 21, 2017

Nice work 👍

Loading

@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
Linked issues

Successfully merging this pull request may close these issues.

2 participants