Added metaclass to create dummy Paramter/Variables #298
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a bit of a hack, but it allows users to force creation of dummy Parameter / Variables instead of symbol ones (see #290).
Usage:
Where in normal
symfit
behaviour the result would be(3, 3)
.Why would you want to use this? Well, if your application of
symfit
is one script, one model kind of fitting then there is probably very little use. But if you make a bigger application where many models are created and active at the same time (thread safe?) then dummy behaviour is desired.Also, lets say you happen to be making your parmeters like this:
Without dummies, these two parameters are the same, and fitting fails without an error. With dummies, it still doesnt work, but at least you get an error :)
Yes, I agree the implementation is a bit sketchy and could be considered dark magic. Suggestions are welcome. Maybe some split of the inheritance into
Parameter
andDummyParameter
, but because of all the implementations of__new__
it seems thatDummy
somehow needs to be introduced just afterArgument
in the mro.The hack via
builtins
is needed because the information on wheter to dummy or not needs to be passed before any symfit imports as that is when the classes are created.builtins
is py3 only (did we drop py2 already?)