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

Fix type hints of parse_obj and similar methods #405

Merged
merged 1 commit into from Feb 21, 2019

Conversation

Projects
None yet
2 participants
@erosennin
Copy link
Contributor

erosennin commented Feb 21, 2019

Change Summary

Methods like BaseModel.parse_obj() or BaseModel.copy() have their return type specified as BaseModel. Because of that, valid code like this:

from pydantic import BaseModel

class User(BaseModel):
    id: int
    name: str

u = User.parse_obj({
    'id': 11,
    'name': 'Acedia',
})

print(u.id, u.name)

does not type check:

example.py:12: error: "BaseModel" has no attribute "id"
example.py:12: error: "BaseModel" has no attribute "name"

This PR fixes that.

Related issue number

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • HISTORY.rst has been updated
    • if this is the first change since a release, please add a new section
    • include the issue number or this pull request number #<number>
    • include your github username @<whomever>

@erosennin erosennin force-pushed the erosennin:generic-constructors branch from 25edbe8 to aec6968 Feb 21, 2019

@erosennin erosennin changed the title Fix type hints of `parse_obj` and similar methods Fix type hints of parse_obj and similar methods Feb 21, 2019

@codecov

This comment has been minimized.

Copy link

codecov bot commented Feb 21, 2019

Codecov Report

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

@@          Coverage Diff          @@
##           master   #405   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          14     14           
  Lines        2068   2068           
  Branches      420    420           
=====================================
  Hits         2068   2068
@samuelcolvin
Copy link
Owner

samuelcolvin left a comment

otherwise LGTM.

Show resolved Hide resolved pydantic/main.py Outdated
Show resolved Hide resolved HISTORY.rst Outdated

@erosennin erosennin force-pushed the erosennin:generic-constructors branch from aec6968 to 7f336d4 Feb 21, 2019

@erosennin erosennin force-pushed the erosennin:generic-constructors branch from 7f336d4 to c6e5fdd Feb 21, 2019

@erosennin

This comment has been minimized.

Copy link
Contributor Author

erosennin commented Feb 21, 2019

Done.

@samuelcolvin samuelcolvin merged commit e77bc00 into samuelcolvin:master Feb 21, 2019

3 checks passed

codecov/project 100% (+0%) compared to 7cd423a
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
deploy/netlify Deploy preview ready!
Details
@samuelcolvin

This comment has been minimized.

Copy link
Owner

samuelcolvin commented Feb 21, 2019

awesome. Thank you very much.

I'll fix another thing and deploy in a day or two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.