traits
traits copied to clipboard
Deprecate CHECK_INTERFACES and old-style interface checking
I propose that we deprecate the old-style interface-checking machinery in Traits 7.0. Going forward, the recommendation should be that we use the standard library abc
-based machinery.
One key difference is that the old-style interface checks check every single method, as opposed to just those decorated with abstractmethod
. We should prefer the explicit, standard solution.
(Note that there's a lot of history here: the old-style stuff predated the introduction of the abc
module in Python 3.0 / Python 2.6; over time since then, we've been slowly neutering the interface-checking so that it's less intrusive - for example, making the default for CHECK_INTERFACES
equal to 0
, and removing the interface checking on assignment to a trait with trait type Instance(MyInterface)
.)
There's more discussion and more fleshing out of details needed here. In particular, I'd like to keep the Interface
type, but once we remove the old-style interface checking it'll become more-or-less a synonym for ABCHasTraits
. It's still a nice name to indicate "this is a class that we intend to use as an interface - i.e., by registration, rather than by subclassing".
We'd also need to decide what to do about provides
. Without the interface checking, it provides essentially the same functionality as register
, in slightly different form. (But only slightly different. In Python 2, it used to be true that you couldn't use register
as a decorator, but that restriction is gone in Python 3.)
Related: #1217.
Possible alternative: consider developing a static analysis tool (e.g., something that can be integrated into flake8 as as plugin) that can do Traits-aware interface checking. Maybe we'd also want to grow the ability to annotate some traits as abstract (which would be easily done using metadata).
#1231 is merged, so the effect of CHECK_INTERFACES
is deprecated, and that effect can be removed in Traits 7.0. It's probably safe to remove the CHECK_INTERFACES
constant at that point, too.