Skip to content

Type hints for Table.update are inaccurate? #598

@brendan-m-murphy

Description

@brendan-m-murphy

The type hints for Table.update say that if fields is Callable, then it must map Mapping to None. This probably either needs to be Callable[[MutableMapping], None] or Callable[[Mapping], Mapping].

For instance, the delete operation creates a "transform" function that deletes a key. But

def transform(doc: Mapping) -> None:
    del doc[field]

is invalid since Mapping doesn't have __delitem__: https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes.

So either doc should be MutableMapping, or the operation should return the updated doc:

def transform(doc: Mapping) -> dict:
    doc = dict(doc)
    del doc[field]
    return doc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions