Repository: pydantic/pydantic

Issue:
`inherit_config` overwrites `json_encoders` from class creation arguments
### Checks

* [x] I added a descriptive title to this issue
* [x] I have searched (google, github) for similar issues and couldn't find anything
* [x] I have read and followed [the docs](https://pydantic-docs.helpmanual.io/) and still think this is a bug

<!-- Sorry to sound so draconian, but every second saved replying to issues is time spend improving pydantic :-) -->

# Bug

Output of `python -c "import pydantic.utils; print(pydantic.utils.version_info())"`:
```
             pydantic version: 1.8.1
            pydantic compiled: False
                 install path: [...]/lib/python3.9/site-packages/pydantic
               python version: 3.9.2 (default, Feb 21 2021, 06:38:26)  [Clang 7.1.0 (tags/RELEASE_710/final)]
                     platform: macOS-10.14.6-x86_64-i386-64bit
     optional deps. installed: ['typing-extensions']
```
<!-- or if you're using pydantic prior to v1.3, manually include: OS, python version and pydantic version -->

<!-- Please read the [docs](https://pydantic-docs.helpmanual.io/) and search through issues to
confirm your bug hasn't already been reported. -->

<!-- Where possible please include a self-contained code snippet describing your bug: -->

```py
import pydantic

class Foo(pydantic.BaseModel):
    class Config:
        json_encoders = {int: str}

print('Foo json_encoders:', Foo.__config__.json_encoders)


class Bar(pydantic.BaseModel, json_encoders={int: str}):
    pass

print('Bar json_encoders:', Bar.__config__.json_encoders)
```

Output:

```
Foo json_encoders: {<class 'int'>: <class 'str'>}
Bar json_encoders: {}
```

Culprit:

https://github.com/samuelcolvin/pydantic/blob/62bb2ad4921016df51abf3922c3fe51113b08939/pydantic/main.py#L184-L187
`inherit_config` overwrites `json_encoders` from class creation arguments
### Checks

* [x] I added a descriptive title to this issue
* [x] I have searched (google, github) for similar issues and couldn't find anything
* [x] I have read and followed [the docs](https://pydantic-docs.helpmanual.io/) and still think this is a bug

<!-- Sorry to sound so draconian, but every second saved replying to issues is time spend improving pydantic :-) -->

# Bug

Output of `python -c "import pydantic.utils; print(pydantic.utils.version_info())"`:
```
             pydantic version: 1.8.1
            pydantic compiled: False
                 install path: [...]/lib/python3.9/site-packages/pydantic
               python version: 3.9.2 (default, Feb 21 2021, 06:38:26)  [Clang 7.1.0 (tags/RELEASE_710/final)]
                     platform: macOS-10.14.6-x86_64-i386-64bit
     optional deps. installed: ['typing-extensions']
```
<!-- or if you're using pydantic prior to v1.3, manually include: OS, python version and pydantic version -->

<!-- Please read the [docs](https://pydantic-docs.helpmanual.io/) and search through issues to
confirm your bug hasn't already been reported. -->

<!-- Where possible please include a self-contained code snippet describing your bug: -->

```py
import pydantic

class Foo(pydantic.BaseModel):
    class Config:
        json_encoders = {int: str}

print('Foo json_encoders:', Foo.__config__.json_encoders)


class Bar(pydantic.BaseModel, json_encoders={int: str}):
    pass

print('Bar json_encoders:', Bar.__config__.json_encoders)
```

Output:

```
Foo json_encoders: {<class 'int'>: <class 'str'>}
Bar json_encoders: {}
```

Culprit:

https://github.com/samuelcolvin/pydantic/blob/62bb2ad4921016df51abf3922c3fe51113b08939/pydantic/main.py#L184-L187


Comments:

Patch:
diff --git a/pydantic/main.py b/pydantic/main.py
--- a/pydantic/main.py
+++ b/pydantic/main.py
@@ -184,6 +184,7 @@ def inherit_config(self_config: 'ConfigType', parent_config: 'ConfigType', **nam
     namespace['json_encoders'] = {
         **getattr(parent_config, 'json_encoders', {}),
         **getattr(self_config, 'json_encoders', {}),
+        **namespace.get('json_encoders', {}),
     }
 
     return type('Config', base_classes, namespace)


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -1723,6 +1723,13 @@ class Model(Base, extra='allow'):
     assert Model.__fields__['b'].alias == 'B'  # alias_generator still works
 
 
+def test_class_kwargs_config_json_encoders():
+    class Model(BaseModel, json_encoders={int: str}):
+        pass
+
+    assert Model.__config__.json_encoders == {int: str}
+
+
 def test_class_kwargs_config_and_attr_conflict():
 
     with pytest.raises(