|
1 | 1 | """Resource class that forms the base of all DID Document components."""
|
2 | 2 | from abc import ABC, abstractmethod
|
3 | 3 | import json
|
4 |
| -from typing import Any, Dict, Type, TypeVar, cast |
| 4 | +from typing import Any, Dict, Type, TypeVar |
5 | 5 |
|
6 | 6 | from inflection import camelize
|
7 | 7 | from pydantic import BaseModel, Extra, parse_obj_as
|
@@ -126,16 +126,14 @@ def dereference(self, reference: str) -> Resource:
|
126 | 126 | def dereference_as(self, typ: Type[ResourceType], reference: str) -> ResourceType:
|
127 | 127 | """Dereference a resource to a specific type."""
|
128 | 128 | resource = self.dereference(reference)
|
129 |
| - if not isinstance(resource, typ): |
130 |
| - try: |
131 |
| - resource = typ(**resource.dict()) |
132 |
| - except ValueError as error: |
133 |
| - raise ValueError( |
134 |
| - "Dereferenced resource {} could not be parsed as {}".format( |
135 |
| - resource, typ.__name__ |
136 |
| - ) |
137 |
| - ) from error |
138 |
| - return cast(typ, resource) |
| 129 | + try: |
| 130 | + return parse_obj_as(typ, resource.dict()) |
| 131 | + except ValueError as error: |
| 132 | + raise ValueError( |
| 133 | + "Dereferenced resource {} could not be parsed as {}".format( |
| 134 | + resource, typ.__name__ |
| 135 | + ) |
| 136 | + ) from error |
139 | 137 |
|
140 | 138 | @classmethod
|
141 | 139 | def construct(cls, **data):
|
|
0 commit comments