secondmind-labs / trieste

A Bayesian optimization toolbox built on TensorFlow
Apache License 2.0
212 stars 41 forks source link

Extending ProbablisticModel protocol hierarchy breaks isinstance checks #836

Open uri-granta opened 3 months ago

uri-granta commented 3 months ago

Running the following code snippet in a fresh Python 3.10 venv with trieste installed via pip:

from trieste.models.interfaces import ProbabilisticModel
from typing import Protocol
class SomeProbabilisticModel(ProbabilisticModel, Protocol): pass
assert not isinstance(1, ProbabilisticModel)

results in the following error:

TypeError: Protocols with non-method members don't support issubclass()

Removing the SomeProbabilisticModel definition on line 3 fixes the issue, as does moving the definition into trieste itself. It also seems to be fixed with Python 3.12.

It would be nice to figure out what is causing this, as it prevents us from reliably being able to use isinstance checks.