Skip to content

type-specific item_get() wrapper methods #124

@zcutlip

Description

@zcutlip

I think it would be useful to have methods that wrap OP.item_get() and return a specific op item type.

This would have at least two benefits:

  • It would help type-aware environments by returning concrete types rather than OPAbstractItem
  • It could perform validation and raise an exception if the returned type isn't what the caller was expecting

I'm picturing something like:

def item_get_login(self, item_identifier, vault=None, ...) -> OPLoginItem:
    item = self.item_get(item_identifier, vault=vault, ...)
    if not isinstance(item, OPLoginItem):
        # ValueError or maybe something more specific
        raise ValueError(f"Unexpected item type for item {item_identifier}. Expected OPLoginItem")
    return item

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions