batavia icon indicating copy to clipboard operation
batavia copied to clipboard

Implement a function to check valid types for a type.

Open ramiroluz opened this issue 8 years ago • 2 comments

A valid function in utils would receive a type name parameter and return true if the type is compatible with the name.

Example:

  • other is a batavia.types.Bool: valid('Bool', other) -> true
  • other is a batavia.types.Int: valid('Bool', other) -> true
  • other is a batavia.types.Float: valid('Bool', other) -> true
  • other is a batavia.types.Dict: valid('Bool', other) -> false

It could be used in places like this one: https://github.com/pybee/batavia/blob/master/batavia/types/Bool.js#L58

And refactor other parts: https://github.com/pybee/batavia/blob/master/batavia/types/Bool.js#L124

ramiroluz avatar Oct 22 '16 01:10 ramiroluz

Could you provide an example of how you'd use this in practice? Simplifying the logic in operators would definitely be nice, but it isn't clear to me that defining a valid() method like the one you describe would make things cleaner.

A working code example would be very helpful - it doesn't have to be rolled out through the whole of Batavia (or even the whole of Bool) - just something to illustrate what you're suggesting.

freakboy3742 avatar Oct 22 '16 23:10 freakboy3742

Look at this example: https://github.com/ramiroluz/batavia/commit/e71d4232647c8c710c8502fb2df0de0a38f09c59

I don't think that it is a good idea to change the __pow__ method anymore. The function behave_like doesn't fit there and I am not comfortable changing the __pow__ method.

ramiroluz avatar Oct 23 '16 03:10 ramiroluz