Closed Vardan2009 closed 1 month ago
The errortype should not be like a keyword rather should have to be like a function or class.
Example:
raise TypeError("Invalid type")
Follow #83 for details. Also make sure, all tests are passing.
Thanks for your contribution. Keep it up. 👍🏻
I don't think it will be possible to do it as a class because errors are not currently first-class citizens (try
-catch
gives a string). Also, the current implementation seems to allow any identifier as an error type, which I don't know if it's desirable (but the more I think about it the more I feel it's actually a good idea):
raise shfgsdjkfhg "shfgsdjkfhg moment"
(To be clear, the reason I'm mentioning that is because it wouldn't be possible to do that with classes either. At least not as conveniently)
The errortype should not be like a keyword rather should have to be like a function or class.
I did think doing it with classes, but I thought it will be hard because classes don't support inheritance (like class TypeError : BaseError
).
Maybe it could be function syntax but not actually a function call? Like:
raise FooError("message")
That would be valid, but not actually calling any FooError
function. Just as part of the syntax of raise
That seems like a good idea, but it will still allow any identifier to be an error type
but it will still allow any identifiere to be an error type
Which is, in my opinion, a Good Thing
I think so too
But I still think the idea with a function returning an error message is a better idea Something like:
fun ArgError(arg)
{
return "Argument `"+arg+"` not found"
}
raise ArgError("arg1")
Oooh! Never thought about doing it like that! Thought you would need inheritance to make it work but I guess not. Good idea!
Now the syntax I mentioned above should work as expected, I also added a simple test to the tests
@Vardan2009 You need to test your local code before pushing to Github. Use python3.11 test.py full
for testing everything. But in my opinion you just need to focus on mypy
issue for now. So, mypy .
for just checking Python codes.
Sorry, I was having some problems running the tests on my local machine, but I got it working now. I will try fixing these errors.
Sorry, I was having some problems running the tests on my local machine, but I got it working now. I will try fixing these errors.
Most important is to fix the mypy
issue now.
Thanks, @Vardan2009 mypy
is not complaining anymore.
Also, thanks to @angelcaru for being so helpful.
Stay contributing everyone.
This was my first ever contribution to a project, thank you so much!
This was my first ever contribution to a project, thank you so much!
Your welcome.
@Vardan2009 You can join us here https://discord.gg/zJhwFzqxs7
The syntax: raise errortype expression
Example: raise TypeError "Input must be integer"