Skip to content
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

Added raise statement #135

Merged
merged 23 commits into from
May 25, 2024
Merged

Added raise statement #135

merged 23 commits into from
May 25, 2024

Conversation

Vardan2009
Copy link
Contributor

@Vardan2009 Vardan2009 commented May 19, 2024

The syntax:
raise errortype expression

Example:
raise TypeError "Input must be integer"

Syntax:
raise ErrorType "Error Message"
Things like:

raise RTError 1+1

or

msg = "Error Message"
raise TypeError msg

would work now
@Almas-Ali
Copy link
Member

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. 👍🏻

@angelcaru
Copy link
Contributor

angelcaru commented May 19, 2024

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)

@Vardan2009
Copy link
Contributor Author

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).

@angelcaru
Copy link
Contributor

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

@Vardan2009
Copy link
Contributor Author

That seems like a good idea, but it will still allow any identifier to be an error type

@angelcaru
Copy link
Contributor

but it will still allow any identifiere to be an error type

Which is, in my opinion, a Good Thing

@Vardan2009
Copy link
Contributor Author

I think so too

@Vardan2009
Copy link
Contributor Author

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")

@angelcaru
Copy link
Contributor

Oooh! Never thought about doing it like that! Thought you would need inheritance to make it work but I guess not. Good idea!

Syntax: raise FooError("message")
Now it is only possible to raise errors with function calls
```
fun ArgError(arg)
{
    return "Argument `"+arg+"` not found"
}

raise ArgError("arg1")
```

The name of the function will also be the error type
```
ArgError: Argument `arg1` not found
```
Updated `raise.rn.json` to match the new output
Removed debug line (parser.py:167)
@Vardan2009
Copy link
Contributor Author

Now the syntax I mentioned above should work as expected, I also added a simple test to the tests

@Almas-Ali
Copy link
Member

@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.

@Vardan2009
Copy link
Contributor Author

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.

@Almas-Ali
Copy link
Member

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.

@Almas-Ali
Copy link
Member

Almas-Ali commented May 25, 2024

Thanks, @Vardan2009 mypy is not complaining anymore.
Also, thanks to @angelcaru for being so helpful.

Stay contributing everyone.

@Almas-Ali Almas-Ali merged commit d178d09 into radon-project:master May 25, 2024
1 check passed
@Vardan2009
Copy link
Contributor Author

This was my first ever contribution to a project, thank you so much!

@Almas-Ali
Copy link
Member

This was my first ever contribution to a project, thank you so much!

Your welcome.

@Almas-Ali
Copy link
Member

@Vardan2009 You can join us here https://discord.gg/zJhwFzqxs7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants