Reputation: 316
I have a function implemented in C that is exposed to python (c extension) that accepts a sequence. Its signature looks something like this:
from typing import Sequence
def my_c_func(my_sequence: Sequence[TypeDoesntMatter]):
...
But the thing is, Sequence
generic is way more descriptive than what PySequence_Check
validates as a sequence (source), as documentation for PySequence_Check
clearly states that it returns 1
if an object has __getitem__
magic method, unless it's a dict. Satisfying the first part is easy: creating a custom generic with __getitem__
, but marking that the value cannot be a dictionary or its subclass? - at least according to this answer is impossible.
Why I think that this question is not a duplicate of the already mentioned one? First of, the solution given there doesn't work for my use-case, and secondly, while excluding a dictionary is one of the solutions that could work (if it was possible), It isn't the only theoretical solution that could exist for my issue.
Upvotes: 1
Views: 95