-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix #609 (default arguments for GenericModel) #610
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #610 +/- ##
=======================================
Coverage ? 100%
=======================================
Files ? 15
Lines ? 2582
Branches ? 510
=======================================
Hits ? 2582
Misses ? 0
Partials ? 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should add a test for the case of a default as per the issue
def test_default_arguments():
T = TypeVar('T')
class Result(GenericModel, Generic[T]):
data: T
other: bool = True
result = Result[int](data=1)?
Sorry my comments were confusing -- when I said I added tests not directly related, I meant in addition to one that was. The following test was already committed: @skip_36
def test_default_arguments():
T = TypeVar('T')
class Result(GenericModel, Generic[T]):
data: T
other: bool = True
result = Result[int](data=1)
assert result.other is TrueLet me know if that's not enough |
|
sound more double quotes I'm afraid :-). Promise I'll do linting for this soon. Also, what about class Result(GenericModel, Generic[T]):
data: T = 4Does that work fine? Maybe worth adding a test? |
a7937a8 to
b18da50
Compare
+1 here's an option
I'm not sure if I should be reading anything special into this (e.g., raise errors if T isn't numeric at model creation time?), but it appears to work correctly (or at least, the same as it would if inheriting from BaseModel with T replaced). I added the test. |
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
b18da50 to
d4c4fcf
Compare
…es (pydantic#610) Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
Fix #609 (default arguments for GenericModel)
Checklist
HISTORY.rsthas been updated