Repository: pydantic/pydantic

Issue:
Default values ignored for GenericModel
# Bug
* Python version: 3.7
* Pydantic version: 0.29

This test fails:
```python
def test_default_arguments():
    T = TypeVar('T')

    class Result(GenericModel, Generic[T]):
        data: T
        other: bool = True
    result = Result[int](data=1)
```
with result:
```
E           pydantic.error_wrappers.ValidationError: 1 validation error
E           other
E             field required (type=value_error.missing)
```
I have a simple patch to fix this and will submit it shortly.


Comments:

Patch:
diff --git a/pydantic/generics.py b/pydantic/generics.py
--- a/pydantic/generics.py
+++ b/pydantic/generics.py
@@ -43,7 +43,7 @@ def __class_getitem__(  # type: ignore
         model_name = concrete_name(cls, params)
         validators = gather_validators(cls)
         fields: Dict[str, Tuple[Type[Any], Any]] = {
-            k: (v, getattr(cls, k, ...)) for k, v in concrete_type_hints.items()
+            k: (v, cls.__fields__[k].default) for k, v in concrete_type_hints.items() if k in cls.__fields__
         }
         created_model = create_model(
             model_name=model_name,


Test patch:
diff --git a/tests/test_generics.py b/tests/test_generics.py
--- a/tests/test_generics.py
+++ b/tests/test_generics.py
@@ -1,6 +1,6 @@
 import sys
 from enum import Enum
-from typing import Any, Dict, Generic, List, Optional, TypeVar, Union
+from typing import Any, ClassVar, Dict, Generic, List, Optional, TypeVar, Union
 
 import pytest
 
@@ -33,6 +33,31 @@ class Result(GenericModel, Generic[data_type]):
     assert str(exc_info.value) == 'Cannot parameterize a concrete instantiation of a generic model'
 
 
+@skip_36
+def test_value_validation():
+    T = TypeVar('T')
+
+    class Response(GenericModel, Generic[T]):
+        data: T
+
+        @validator('data')
+        def validate_value_nonzero(cls, v):
+            if isinstance(v, dict):
+                return v  # ensure v is actually a value of the dict, not the dict itself
+            if v == 0:
+                raise ValueError('value is zero')
+
+    with pytest.raises(ValidationError) as exc_info:
+        Response[Dict[int, int]](data={1: 'a'})
+    assert exc_info.value.errors() == [
+        {'loc': ('data', 1), 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}
+    ]
+
+    with pytest.raises(ValidationError) as exc_info:
+        Response[Dict[int, int]](data={1: 0})
+    assert exc_info.value.errors() == [{'loc': ('data', 1), 'msg': 'value is zero', 'type': 'value_error'}]
+
+
 @skip_36
 def test_methods_are_inherited():
     class CustomGenericModel(GenericModel):
@@ -68,6 +93,64 @@ class Model(CustomGenericModel, Generic[T]):
     assert str(exc_info.value) == '"Model[int]" is immutable and does not support item assignment'
 
 
+@skip_36
+def test_default_argument():
+    T = TypeVar('T')
+
+    class Result(GenericModel, Generic[T]):
+        data: T
+        other: bool = True
+
+    result = Result[int](data=1)
+    assert result.other is True
+
+
+@skip_36
+def test_default_argument_for_typevar():
+    T = TypeVar('T')
+
+    class Result(GenericModel, Generic[T]):
+        data: T = 4
+
+    result = Result[int]()
+    assert result.data == 4
+
+    result = Result[float]()
+    assert result.data == 4
+
+    result = Result[int](data=1)
+    assert result.data == 1
+
+
+@skip_36
+def test_classvar():
+    T = TypeVar('T')
+
+    class Result(GenericModel, Generic[T]):
+        data: T
+        other: ClassVar[int] = 1
+
+    assert Result.other == 1
+    assert Result[int].other == 1
+    assert Result[int](data=1).other == 1
+    assert 'other' not in Result.__fields__
+
+
+@skip_36
+def test_non_annotated_field():
+    T = TypeVar('T')
+
+    class Result(GenericModel, Generic[T]):
+        data: T
+        other = True
+
+    assert 'other' in Result.__fields__
+    assert 'other' in Result[int].__fields__
+
+    result = Result[int](data=1)
+    assert result.other is True
+
+
 @skip_36
 def test_must_inherit_from_generic():
     with pytest.raises(TypeError) as exc_info: