Skip to content

Make ArangoClient generic to support typing when a custom serialiser is used #304

Closed as not planned
@marcuslimdw

Description

@marcuslimdw

Currently, the parameters of methods such as insert and aql.execute are typed concretely (with Json and Optional[MutableMapping[str, str]] respectively).

This is overly restrictive because these methods will in fact accept other types, as long as the serialiser in use supports them (and in fact, even the default json.loads serialiser can accept a wider range of types).

My suggestion:

Make ArangoClient, AQL, Database, and Collection generic in their serializer type (with the client's serializer type being passed down to everything created from it), something like this (using Python 3.12's new type parameter syntax):

class Serializer[T](Protocol):

    def __call__(self, value: T) -> Json:
        pass


class ArangoClient[T]:

    def __init__(self, serializer: Serializer[T], *args, **kwargs):
        pass

    def db(self, *args, **kwargs) -> Database[T]:
        pass


class StandardDatabase[T]:

    def collection(self, *args, **kwargs) -> Collection[T]:
        pass

    
class StandardCollection[T]:

    def insert(self, document: T, *args, **kwargs):  # no longer Json
        pass

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy