Skip to content

Fixed ignore_event_type logic. #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/aapi/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,23 @@ class AAPIJob:

class AAPIObject:
def as_aapi_dict(self, ignore_event_type=True):

# Import inside the method to prevent circular import issues
from aapi.ifbase import IfCompletionStatus

res = {}


# Get type if it exists
if '_type' in attrs.fields_dict(self.__class__):
is_condition_or_event = self._type.startswith(('Condition', 'Event'))

if ignore_event_type:
if not is_condition_or_event:
res['Type'] = self._type
elif self._type.startswith('Event'):
res['Type'] = self._type


type_value = self._type
should_ignore_type = ignore_event_type and type_value.startswith(('Event', 'Condition'))
if not should_ignore_type:
res['Type'] = type_value

# Process remaining (non-_type) fields
if attrs.has(self):
for field in attrs.fields(self.__class__):
if field.name == '_type': # type already handled
continue

value = self.__getattribute__(field.name)
aapi_repr = field.metadata.get("_aapi_repr_")

Expand All @@ -42,14 +41,15 @@ def as_aapi_dict(self, ignore_event_type=True):
if aapi_repr:
if "_type_aapi_" in field.metadata:
if "_hide_type_" in field.metadata:
if "Type" in res:
res.__delitem__("Type")
res.pop("Type", None)
continue

# Handle different value types
if "as_aapi_dict" in dir(value):
res[aapi_repr] = value.as_aapi_dict()
elif isinstance(value, list):
res[aapi_repr] = [
(o.as_aapi_dict() if "as_aapi_dict" in dir(o) else o)
o.as_aapi_dict() if "as_aapi_dict" in dir(o) else o
for o in value
]
elif isinstance(value, enum.Enum):
Expand All @@ -61,11 +61,11 @@ def as_aapi_dict(self, ignore_event_type=True):
for obj in value:
obj_ignore_type = ignore_event_type
if isinstance(self, IfCompletionStatus):
obj_ignore_type = False
obj_ignore_type = False
res[obj.object_name] = obj.as_aapi_dict(ignore_event_type=obj_ignore_type)

else:
res["attrsibutes_valid"] = False
res["attributes_valid"] = False

return res

Expand Down