-
Notifications
You must be signed in to change notification settings - Fork 170
decimal module initiated #679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
src/runtime/decimal.py
Outdated
|
||
@overload | ||
def Decimal(x: i64) -> i64: | ||
return x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> from decimal import *
>>> Decimal(1)
Decimal('1')
>>> type(Decimal(1))
<class 'decimal.Decimal'>
Let's start off with something like the following,
@dataclass
class Decimal:
value: str
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove @dataclass
from Decimal
in future. For now using them should be okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc: @certik
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should just implement these the right way, that is, they have to be implemented as a class, that implements some methods that you can then call. So we have to first implement classes in LPython.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it have overloading too? Something like:
@dataclass
class Decimal:
@overload
def Decimal(x: i64) -> i64:
return x
@overload
def Decimal(x: i32) -> i32:
return x
@overload
def Decimal(x: f32) -> f64:
return float(x)
@overload
def Decimal(x: f64) -> f64:
return float(x)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please explain why I am facing this particular error, what should be necessarily done differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can support overloading of methods, but as a second iteration, not first (it might be a bit involved, but doable).
Why don't you open up an issue for what is needed. I think what is needed is support for this:
class Decimal:
def f(x: i64) -> i64:
return x
def g() -> Decimal:
return Decimal()
x: Decimal = g()
print(x.f())
And probably more, but the above is a start. Can you please open up an issue for this? Then let's implement it in LPython. Then you'll abe able to use it, and we can then open up issues for any missing features, etc.
@czgdp1807 please see if this is good for merging, and how can we improve it |
@czgdp1807 can you please review this PR? It looks like @Madhav2310 asked you to review it, but somehow we missed it. |
This requires full class support (especially method calling, object reaction). Data classes alone won't be sufficient to implement this. I discussed this with @Madhav2310 in one of the GSoC weekly meetings and we arrived at the same conclusion. |
No description provided.