rafaqz / Interfaces.jl

Macros to define and implement interfaces, to ensure they are checked and correct.
MIT License
72 stars 4 forks source link

Disabling specific parts of an interface #45

Closed MilesCranmer closed 1 week ago

MilesCranmer commented 1 week ago

Hi @rafaqz,

Nice package! I'm working on adding it to DynamicExpressions.jl to test a few different abstract types: https://github.com/SymbolicML/DynamicExpressions.jl/blob/6c6485a32a63436cee23e0ff837d8653cd6ec223/src/Interfaces.jl#L89.

One question I had is if there is any way to turn off specific parts of an interface? For example, there is a function simplify_tree!. This is technically part of the interface, but there are specific types which break when using it. For those, I want the simplify_tree! call to return a helpful error instead of simply a MethodError – so the user is aware specifically why they shouldn't be trying to simplify that expression.

However I'm not sure the right way to do this. Any tips?

Thanks! Miles

MilesCranmer commented 1 week ago

Ah, sorry, didn't realise I actually needed to pass all the optional methods as type parameters. So I can just not pass certain tests!

rafaqz commented 1 week ago

Yeah, when you use the @implements macro you can specify the options you have implemented.

That's then reflected in the available implements traits and in what will be tested in test

MilesCranmer commented 1 week ago

Oh, that's cool. Thanks!