vaticle / typedb-driver

TypeDB Drivers for Rust, Python, Java, Node.js, C, C++, and C#.
https://typedb.com
Apache License 2.0
30 stars 32 forks source link

Type hint in signature of `Thing.get_relations` is incorrect #613

Closed james-whiteside closed 2 months ago

james-whiteside commented 3 months ago

Description

Thing.get_relations has the following signature:

get_relations(self, transaction: TypeDBTransaction, role_types: list[RoleType] = None) -> Iterator[Relation]

This is incorrect, as argument role_types can also be of type RoleType (tested), so the signature should probably be:

get_relations(self, transaction: TypeDBTransaction, role_types: RoleType | list[RoleType] = None) -> Iterator[Relation]

Environment

  1. Driver version: Python 2.26.6
farost commented 2 months ago

@james-whiteside Actually, you're right that passing a value there works, but the current interface looks wrong (and it's sad that python doesn't help much with checking it). The inner method accepts *role_types: RoleType as a variable number of arguments, and it can't accept a list: it would convert it to a tuple of lists of values instead of a tuple of values.

I've written a small test which sends a list to this method (not worth pushing), and it highlighted this issue as well:

native_role_types = [rt.native_object for rt in role_types]
AttributeError: 'list' object has no attribute 'native_object'

We have a similar situation with get_players_by_role_type, but there we have matching interface and implementation contracts: *role_types: _RoleType.

I believe that there is a bug in the interface, and I'm going to change it to match the implementation contract. Gonna merge it as a part of https://github.com/vaticle/typedb-driver/pull/623.

farost commented 2 months ago

The connected PR is merged, so the updated API will be a part of the next release.