Cannot overwrite the __str__ method in jitclass
See original GitHub issueHello,
I am not able to overwrite the string representation of a jitclass. I do not know if this is a wanted behaviour though.
from numba.experimental import jitclass
from numba import float64
spec = [("alpha", float64)]
@jitclass(spec)
class Foo:
def __init__(self, alpha):
self.alpha = alpha
def __str__(self):
return "Class Foo"
foo = Foo(1.)
print(str(foo))
Produces:
<numba.experimental.jitclass.boxing.Foo object at 0xS0M3wh3r3>
Expected:
Class Foo
It seems that the __str__() method is skipped entirely, in fact the following does not produce any ZeroDivisionError.
...
def __str__(self):
return 0 ** (-2)
Tested on:
Platform: Linux-5.15.0-52-generic-x86_64-with-glibc2.35
Python version: 3.9.7 (default, Sep 20 2022, 16:21:01)
[GCC 11.2.0]
Numba version: 0.55.2
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to update a jitclass variable with its string name by ...
Here is a solution I came up with. I first wrote a function that return a list of the variable names I can...
Read more >Implementation of __repr__ method within jitclass #8533
Hello, Numba 0.56.0 has introduced support for many builtins for the numba.experimental.jitclass type. Would it be possible to add __repr__, ...
Read more >Compiling Python classes with @jitclass - Numba
Calling static methods as class attributes is only supported outside of the class definition (i.e. you can't call Bag.add() from within another method...
Read more >Compiling Python classes with @jitclass
We call the resulting class object a jitclass. All methods of a jitclass are compiled into nopython functions. The data of a jitclass...
Read more >How do I nest dict-of-jitclass - Support - Numba Discussion
I suspect that this is a bug, Numba's trying to serialize something for the purposes of box/unboxing the data from the CPython interpreter...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

No problem, glad it is working now.
I suggest opening a feature request if it is important to you. I think it’s technically possible to support it.
Great, many thanks. I’ll close this issue as resolved.