Skip to content

Update type annotation for create_model function#2071

Merged
samuelcolvin merged 2 commits intopydantic:masterfrom
uriyyo:create-model-type-annotation
Nov 29, 2020
Merged

Update type annotation for create_model function#2071
samuelcolvin merged 2 commits intopydantic:masterfrom
uriyyo:create-model-type-annotation

Conversation

@uriyyo
Copy link
Copy Markdown
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
Copy Markdown

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
Comment thread pydantic/main.py
@uriyyo uriyyo requested a review from PrettyWood October 29, 2020 18:41
Copy link
Copy Markdown
Contributor

@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
Copy Markdown
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
Copy Markdown
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.

3 participants