I see, thanks for the clear explanation, indeed "100" * a is absurd.

Still, should there at least be some mechanism to handle `int` in this code path? Since the path for `_mul_` works:

```
sage: class Number(Parent):
....:     def __init__(self, x): self.x = x
....:     def __repr__(self): return f"Number({self.x})"
....:     def _mul_(self, other): return Number(self.x * ZZ(other))
....:
....: a = Number(5)
....: a * ZZ(3)
....: a * int(3)
Number(15)
Number(15)
```

On 12/02/2024 17:43, Nils Bruin wrote:


On Monday 12 February 2024 at 03:21:36 UTC-8 Gareth Ma wrote:

    sage: class Number:
    ....:     def __init__(self, x): self.x = x
    ....:     def __repr__(self): return f"Number({self.x})"
    ....:     def _acted_upon_(self, other, _): return Number(self.x *
    ZZ(other))


I think that would have horrible side effects. With that code and your proposed change, I think

"100" * a

should succeed and hence lead to the discovery (and caching!) of an action of "str" on "Number". I would expect that _acted_upon_ should be pretty sure of the objects it handles and not rely on generic "try and convert this" operations.

Another place where Parent may be needed is in the caching code itself: some of it happens in (partially weak) global dictionaries, but some of it happens *on the parent*. So `int` would probably fail to have the appropriate infrastructure for caching.

--
You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/a7ae43b1-d186-4ca1-a754-c669eec7b6e5n%40googlegroups.com <https://groups.google.com/d/msgid/sage-devel/a7ae43b1-d186-4ca1-a754-c669eec7b6e5n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/33de7ced-d088-47ae-a216-ea1886e14bbb%40gmail.com.

Reply via email to