Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
ruscoder committed Oct 2, 2024
1 parent 52bb1ef commit 86103b5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.14

* Minor type fixes

## 2.0.13

* Add support for resource type and reference for client methods get/patch/delete (#133)
Expand Down
2 changes: 1 addition & 1 deletion fhirpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .lib import AsyncFHIRClient, SyncFHIRClient

__title__ = "fhir-py"
__version__ = "2.0.13"
__version__ = "2.0.14"
__author__ = "beda.software"
__license__ = "None"
__copyright__ = "Copyright 2024 beda.software"
Expand Down
2 changes: 1 addition & 1 deletion fhirpy/base/lib_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def save(
_search_params: Union[dict, None] = None,
# _as_dict is a private api used internally
_as_dict: bool = False,
) -> Union[TResource, Any]:
) -> Union[TResource, dict]:
data = serialize(self.dump_resource(resource), drop_nulls_from_dicts=fields is None)
if fields:
if not resource.id:
Expand Down
20 changes: 13 additions & 7 deletions fhirpy/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AsyncFHIRSearchSet(Generic[TResource], AsyncSearchSet["AsyncFHIRClient", T
class BaseFHIRResource(
Generic[TClient, TResource, TReference], BaseResource[TClient, TResource, TReference], ABC
):
def is_reference(self, value):
def is_reference(self, value) -> bool:
if not isinstance(value, dict):
return False

Expand All @@ -55,11 +55,11 @@ class BaseFHIRReference(
Generic[TClient, TResource, TReference], BaseReference[TClient, TResource, TReference], ABC
):
@property
def reference(self):
def reference(self) -> str:
return self["reference"]

@property
def id(self):
def id(self) -> Union[str, None]:
"""
Returns id if reference specifies to the local resource
"""
Expand All @@ -69,7 +69,7 @@ def id(self):
return None

@property
def resource_type(self):
def resource_type(self) -> Union[str, None]:
"""
Returns resource type if reference specifies to the local resource
"""
Expand All @@ -79,7 +79,7 @@ def resource_type(self):
return None

@property
def is_local(self):
def is_local(self) -> bool:
return self.reference.count("/") == 1


Expand All @@ -98,7 +98,13 @@ class AsyncFHIRReference(


class SyncFHIRClient(SyncClient):
def reference(self, resource_type=None, id=None, reference=None, **kwargs): # noqa: A002
def reference(
self,
resource_type=None,
id=None, # noqa: A002
reference=None,
**kwargs,
) -> SyncFHIRReference:
if resource_type and id:
reference = f"{resource_type}/{id}"

Expand Down Expand Up @@ -143,7 +149,7 @@ def reference(
id: Union[str, None] = None, # noqa: A002
reference: Union[str, None] = None,
**kwargs,
):
) -> AsyncFHIRReference:
if resource_type and id:
reference = f"{resource_type}/{id}"

Expand Down

0 comments on commit 86103b5

Please sign in to comment.