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

Update type annotation for create_model function #2071

Merged
merged 2 commits into from Nov 29, 2020

Conversation

uriyyo
Copy link
Contributor

@uriyyo uriyyo commented Oct 29, 2020

Update type annotation for create_model function

Updated create_model return type annotation to return type which inherits from __base__ argument.

For instance, before this PR mypy will fail on the code below:

from pydantic import BaseModel, create_model

class Point(BaseModel):
    x: int
    y: int

NewPoint = create_model('NewPoint', __base__=Point)

point = NewPoint.parse_obj(...)
point.x = 10  # mypy will fail here

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)

@codecov
Copy link

codecov bot commented Oct 29, 2020

Codecov Report

Merging #2071 into master will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##            master     #2071   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         4096      4096           
  Branches       821       821           
=========================================
  Hits          4096      4096           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8dcc87c...8725a18. Read the comment docs.

@uriyyo uriyyo force-pushed the create-model-type-annotation branch from 211264c to 4999f2a Compare October 29, 2020 15:40
pydantic/main.py Outdated Show resolved Hide resolved
Copy link
Member

@PrettyWood PrettyWood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks !

@samuelcolvin
Copy link
Member

this looks good. As far as I'm aware it shouldn't be included in v1.7.2 so I won't merge it yet.

let me know if I'm missing something.

@samuelcolvin samuelcolvin merged commit 5506d8e into pydantic:master Nov 29, 2020
@samuelcolvin
Copy link
Member

thanks a lot.

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.

None yet

3 participants