diff --git a/sdk/healthdataaiservices/azure-health-deidentification/CHANGELOG.md b/sdk/healthdataaiservices/azure-health-deidentification/CHANGELOG.md index be2efaec75db..76b4efaeb6ba 100644 --- a/sdk/healthdataaiservices/azure-health-deidentification/CHANGELOG.md +++ b/sdk/healthdataaiservices/azure-health-deidentification/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.0.0b3 (Unreleased) + +### Bugs Fixed + +Fixed tox pyright errors present in the build (Argument of type "Unknown" and Cannot access attribute) + ## 1.0.0b2 (Unreleased) ### Features Added diff --git a/sdk/healthdataaiservices/azure-health-deidentification/azure/health/deidentification/_model_base.py b/sdk/healthdataaiservices/azure-health-deidentification/azure/health/deidentification/_model_base.py index 43fd8c7e9b1b..1c8c67e86672 100644 --- a/sdk/healthdataaiservices/azure-health-deidentification/azure/health/deidentification/_model_base.py +++ b/sdk/healthdataaiservices/azure-health-deidentification/azure/health/deidentification/_model_base.py @@ -323,15 +323,27 @@ def _get_type_alias_type(module_name: str, alias_name: str): return types[alias_name] -def _get_model(module_name: str, model_name: str): +def _get_model(module_name: str, model_name: typing.Union[str, typing.ForwardRef]) -> typing.Any: models = {k: v for k, v in sys.modules[module_name].__dict__.items() if isinstance(v, type)} module_end = module_name.rsplit(".", 1)[0] models.update({k: v for k, v in sys.modules[module_end].__dict__.items() if isinstance(v, type)}) - if isinstance(model_name, str): - model_name = model_name.split(".")[-1] - if model_name not in models: - return model_name - return models[model_name] + + # Get the actual name string from the ForwardRef if that's what we received + if isinstance(model_name, typing.ForwardRef): + name_str = typing.cast(str, getattr(model_name, "__forward_arg__", "")) + else: + name_str = typing.cast(str, model_name) if model_name else "" + + if isinstance(name_str, str): + name_str = name_str.split(".")[-1] + + # Look up the model class by name + if not isinstance(name_str, str): + raise ValueError("Model name must be a string or ForwardRef") + + if name_str not in models: + return name_str + return models[name_str] _UNSET = object() @@ -432,7 +444,7 @@ def _serialize(o, format: typing.Optional[str] = None): # pylint: disable=too-m if isinstance(o, dict): return {k: _serialize(v, format) for k, v in o.items()} if isinstance(o, set): - return {_serialize(x, format) for x in o} + return list(_serialize(x, format) for x in o) # Convert to list to avoid hashability issues if isinstance(o, tuple): return tuple(_serialize(x, format) for x in o) if isinstance(o, (bytes, bytearray)): diff --git a/sdk/healthdataaiservices/azure-health-deidentification/azure/health/deidentification/_serialization.py b/sdk/healthdataaiservices/azure-health-deidentification/azure/health/deidentification/_serialization.py index 8139854b97bb..59b2b2dc322b 100644 --- a/sdk/healthdataaiservices/azure-health-deidentification/azure/health/deidentification/_serialization.py +++ b/sdk/healthdataaiservices/azure-health-deidentification/azure/health/deidentification/_serialization.py @@ -1585,10 +1585,20 @@ def _instantiate_model(self, response, attrs, additional_properties=None): if callable(response): subtype = getattr(response, "_subtype_map", {}) try: - readonly = [k for k, v in response._validation.items() if v.get("readonly")] - const = [k for k, v in response._validation.items() if v.get("constant")] + if isinstance(response, type): + readonly = [k for k, v in response._validation.items() if v.get("readonly")] + else: + readonly = [] + if isinstance(response, type): + const = [k for k, v in response._validation.items() if v.get("constant")] + else: + const = [] kwargs = {k: v for k, v in attrs.items() if k not in subtype and k not in readonly + const} - response_obj = response(**kwargs) + if isinstance(response, type) and issubclass(response, Model): + response_obj = response(**kwargs) + else: + raise TypeError("Response is not a subclass of Model") + for attr in readonly: setattr(response_obj, attr, attrs.get(attr)) if additional_properties: diff --git a/sdk/healthdataaiservices/azure-health-deidentification/azure/health/deidentification/_version.py b/sdk/healthdataaiservices/azure-health-deidentification/azure/health/deidentification/_version.py index bbcd28b4aa67..c43fdbc2e239 100644 --- a/sdk/healthdataaiservices/azure-health-deidentification/azure/health/deidentification/_version.py +++ b/sdk/healthdataaiservices/azure-health-deidentification/azure/health/deidentification/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "1.0.0b2" +VERSION = "1.0.0b3"