Skip to content

Commit

Permalink
Fix backward compatibility for client resource/resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ruscoder committed Aug 5, 2024
1 parent a633f72 commit 294b6e3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.0.1
* Fix backward compatibility for client resource/resources

## 2.0.0
* Add typehints for all methods
* Add pluggable data model #126
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.0"
__version__ = "2.0.1"
__author__ = "beda.software"
__license__ = "None"
__copyright__ = "Copyright 2024 beda.software"
Expand Down
39 changes: 32 additions & 7 deletions fhirpy/base/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from abc import ABC, abstractmethod
from typing import Any, TypeVar, Union

Expand All @@ -14,6 +15,16 @@ class AbstractClient(ABC):
authorization: Union[str, None]
extra_headers: Union[dict, None]

# Deprecated
@property # pragma: no cover
def searchset_class(self):
raise NotImplementedError()

# Deprecated
@property # pragma: no cover
def resource_class(self):
raise NotImplementedError()

def __init__(
self,
url: str,
Expand All @@ -34,13 +45,27 @@ def __repr__(self):
def reference(self, resource_type=None, id=None, reference=None, **kwargs): # noqa: A002
pass

@abstractmethod
def resource(self, resource_type, **kwargs):
pass

@abstractmethod
def resources(self, resource_type):
pass
def resource(self, resource_type, **kwargs): # pragma: no cover
warnings.warn(
"class var `resource_class` is deprecated "
"and will be removed in future versions. "
"Please redefine `resource` method of client",
DeprecationWarning,
stacklevel=2,
)

return self.resource_class(self, resource_type=resource_type, **kwargs)

def resources(self, resource_type): # pragma: no cover
warnings.warn(
"class var `searchset_class` is deprecated "
"and will be removed in future versions. "
"Please redefine `resource` method of client",
DeprecationWarning,
stacklevel=2,
)

return self.searchset_class(self, resource_type=resource_type)

@abstractmethod
def execute(
Expand Down

0 comments on commit 294b6e3

Please sign in to comment.