Skip to content

Commit

Permalink
Merge pull request #169 from radon-project/mypy-strict-passing
Browse files Browse the repository at this point in the history
Mypy strict passing.
  • Loading branch information
Almas-Ali authored Jul 24, 2024
2 parents 97b5272 + c91e483 commit b69126f
Show file tree
Hide file tree
Showing 29 changed files with 256 additions and 376 deletions.
6 changes: 3 additions & 3 deletions core/builtin_classes/file_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ def read(self, ctx: Context) -> RTResult[Value]:

@args([])
@method
def readline(ctx):
def readline(self, ctx: Context):
res = RTResult[Value]()
self = ctx.symbol_table.get("this")
try:
value = self.file.readline()
return res.success(String(value))
except OSError as e:
return res.failure(RTError(None, None, f"Could not read from file: {e.strerror}", None))
pos = Position(-1, -1, -1, "<idk>", "<idk>")
return res.failure(RTError(pos, pos, f"Could not read from file: {e.strerror}", ctx))

@args([])
@method
Expand Down
6 changes: 3 additions & 3 deletions core/builtin_classes/string_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ def endswith(self, ctx: Context) -> RTResult[Value]:
)
return res.success(Boolean(self.value.endswith(string.value)))

@args(["string"], [String("")])
@args(["string"], [String(" ")])
@method
def split(self, ctx: Context) -> RTResult[Value]:
res = RTResult[Value]()
string = ctx.symbol_table.get("string")
string = ctx.symbol_table.get("string") # String object
assert string is not None
if not isinstance(string, String):
return res.failure(RTError(string.pos_start, string.pos_end, "Cannot split a non-string", string.context))
return res.success(Array([String(i) for i in self.value.split(string.value)]))
return res.success(Array([String(i) for i in self.value.split(str(string))]))

@args(["string"], [String("")])
@method
Expand Down
4 changes: 2 additions & 2 deletions examples/args_test.rn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Argparser
import argparser

parser = Argparser.Argparser()
var parser = argparser.Argparser()
parser.add_flag("--version", "-v", "Show version")
parser.add_named("--output", "Output file")
parser.add_pos_opt("filename", "File")
Expand Down
6 changes: 3 additions & 3 deletions examples/arrays.rn
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Array
import array

arr = Array.Array([1,2,3,4,5,6,7,8,9,10])
const arr = array.Array([1,2,3,4,5,6,7,8,9,10])
arr.append(11)
print(arr.to_string())

arr.pop(0)
print(arr.to_string())

print(arr.len())
print(len(arr))

arr.extend(["this", "is", "a", "array"])
print(arr.to_string())
Expand Down
8 changes: 4 additions & 4 deletions examples/classes.rn
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class Person {
}

print("Enter a name, or type 'exit' to quit.")
inp = input("Name: ")
var inp = input("Name: ")

while inp != "exit" {
p = Person(inp)
var p = Person(inp)
print(p.Format())
inp = input("Name: ")
p.single_line()
Expand All @@ -30,6 +30,6 @@ class Some {
fun to_object() -> "Name is : "+ this.name + " Value is : "+ str(this.value)
}

cls_ = Some()
obj = cls_.to_object()
var cls_ = Some()
var obj = cls_.to_object()
print(obj)
110 changes: 55 additions & 55 deletions examples/colors_test.rn
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
import Colorlib
import colorlib

# Print colored text to the console using the colorlib library
print(Colorlib.white("My name is John Doe"))
print(Colorlib.red("My name is John Doe"))
print(Colorlib.green("My name is John Doe"))
print(Colorlib.yellow("My name is John Doe"))
print(Colorlib.blue("My name is John Doe"))
print(Colorlib.purple("My name is John Doe"))
print(Colorlib.cyan("My name is John Doe"))
print(Colorlib.gray("My name is John Doe"))
print(Colorlib.black("My name is John Doe"))
print(Colorlib.bgWhite("My name is John Doe"))
print(Colorlib.bgRed("My name is John Doe"))
print(Colorlib.bgGreen("My name is John Doe"))
print(Colorlib.bgYellow("My name is John Doe"))
print(Colorlib.bgBlue("My name is John Doe"))
print(Colorlib.bgPurple("My name is John Doe"))
print(Colorlib.bgCyan("My name is John Doe"))
print(Colorlib.bgGray("My name is John Doe"))
print(Colorlib.bgBlack("My name is John Doe"))
print(Colorlib.bold("My name is John Doe"))
print(Colorlib.italic("My name is John Doe"))
print(Colorlib.underline("My name is John Doe"))
print(Colorlib.inverse("My name is John Doe"))
print(Colorlib.hidden("My name is John Doe"))
print(Colorlib.strikethrough("My name is John Doe"))
print(Colorlib.blackBright("My name is John Doe"))
print(Colorlib.redBright("My name is John Doe"))
print(Colorlib.greenBright("My name is John Doe"))
print(Colorlib.yellowBright("My name is John Doe"))
print(Colorlib.blueBright("My name is John Doe"))
print(Colorlib.purpleBright("My name is John Doe"))
print(Colorlib.cyanBright("My name is John Doe"))
print(Colorlib.whiteBright("My name is John Doe"))
print(Colorlib.bgBlackBright("My name is John Doe"))
print(Colorlib.bgRedBright("My name is John Doe"))
print(Colorlib.bgGreenBright("My name is John Doe"))
print(Colorlib.bgYellowBright("My name is John Doe"))
print(Colorlib.bgBlueBright("My name is John Doe"))
print(Colorlib.bgPurpleBright("My name is John Doe"))
print(Colorlib.bgCyanBright("My name is John Doe"))
print(Colorlib.bgWhiteBright("My name is John Doe"))
print(Colorlib.reset("My name is John Doe"))
print(Colorlib.bold("My name is John Doe"))
print(Colorlib.italic("My name is John Doe"))
print(Colorlib.underline("My name is John Doe"))
print(Colorlib.inverse("My name is John Doe"))
print(Colorlib.hidden("My name is John Doe"))
print(Colorlib.strikethrough("My name is John Doe"))
print(Colorlib.bgReset("My name is John Doe"))
print(Colorlib.bgBoldBright("My name is John Doe"))
print(colorlib.white("My name is John Doe"))
print(colorlib.red("My name is John Doe"))
print(colorlib.green("My name is John Doe"))
print(colorlib.yellow("My name is John Doe"))
print(colorlib.blue("My name is John Doe"))
print(colorlib.purple("My name is John Doe"))
print(colorlib.cyan("My name is John Doe"))
print(colorlib.gray("My name is John Doe"))
print(colorlib.black("My name is John Doe"))
print(colorlib.bgWhite("My name is John Doe"))
print(colorlib.bgRed("My name is John Doe"))
print(colorlib.bgGreen("My name is John Doe"))
print(colorlib.bgYellow("My name is John Doe"))
print(colorlib.bgBlue("My name is John Doe"))
print(colorlib.bgPurple("My name is John Doe"))
print(colorlib.bgCyan("My name is John Doe"))
print(colorlib.bgGray("My name is John Doe"))
print(colorlib.bgBlack("My name is John Doe"))
print(colorlib.bold("My name is John Doe"))
print(colorlib.italic("My name is John Doe"))
print(colorlib.underline("My name is John Doe"))
print(colorlib.inverse("My name is John Doe"))
print(colorlib.hidden("My name is John Doe"))
print(colorlib.strikethrough("My name is John Doe"))
print(colorlib.blackBright("My name is John Doe"))
print(colorlib.redBright("My name is John Doe"))
print(colorlib.greenBright("My name is John Doe"))
print(colorlib.yellowBright("My name is John Doe"))
print(colorlib.blueBright("My name is John Doe"))
print(colorlib.purpleBright("My name is John Doe"))
print(colorlib.cyanBright("My name is John Doe"))
print(colorlib.whiteBright("My name is John Doe"))
print(colorlib.bgBlackBright("My name is John Doe"))
print(colorlib.bgRedBright("My name is John Doe"))
print(colorlib.bgGreenBright("My name is John Doe"))
print(colorlib.bgYellowBright("My name is John Doe"))
print(colorlib.bgBlueBright("My name is John Doe"))
print(colorlib.bgPurpleBright("My name is John Doe"))
print(colorlib.bgCyanBright("My name is John Doe"))
print(colorlib.bgWhiteBright("My name is John Doe"))
print(colorlib.reset("My name is John Doe"))
print(colorlib.bold("My name is John Doe"))
print(colorlib.italic("My name is John Doe"))
print(colorlib.underline("My name is John Doe"))
print(colorlib.inverse("My name is John Doe"))
print(colorlib.hidden("My name is John Doe"))
print(colorlib.strikethrough("My name is John Doe"))
print(colorlib.bgReset("My name is John Doe"))
print(colorlib.bgBoldBright("My name is John Doe"))

# chaining multiple styles and Colorlibs combined multiple times
print(Colorlib.bold(Colorlib.bgPurple(Colorlib.white("My name is John Doe"))))
print(Colorlib.italic(Colorlib.bgRed(Colorlib.green("My name is John Doe"))))
print(Colorlib.underline(Colorlib.bgYellow(Colorlib.blue("My name is John Doe"))))
print(Colorlib.inverse(Colorlib.bgBlue(Colorlib.yellow("My name is John Doe"))))
# chaining multiple styles and colorlibs combined multiple times
print(colorlib.bold(colorlib.bgPurple(colorlib.white("My name is John Doe"))))
print(colorlib.italic(colorlib.bgRed(colorlib.green("My name is John Doe"))))
print(colorlib.underline(colorlib.bgYellow(colorlib.blue("My name is John Doe"))))
print(colorlib.inverse(colorlib.bgBlue(colorlib.yellow("My name is John Doe"))))
17 changes: 8 additions & 9 deletions examples/files.rn
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@

const f = File("examples/files.rn")
const contents = f.read()
f.close()
f.is_closed()
const f1 = File("examples/files.rn")
const contents = f1.read()
f1.close()
f1.is_closed()

print(contents)

print("-------------")

f = File("examples/files.rn")
print(f.readline())
print(f.readlines())
const f2 = File("examples/files.rn")
print(f2.readline())
print(f2.readlines())

f.close()
f2.close()
31 changes: 0 additions & 31 deletions examples/functions.rn

This file was deleted.

6 changes: 3 additions & 3 deletions examples/hashmap.rn
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# HashMap data type in Radon

hashmap = {
var hashmap = {
"name": "John",
"age": 23,
"address": "123 Main St"
}
print(hashmap)

value = hashmap["name"]
var value = hashmap["name"]
print(value)

hashmap["bcd"] = 234
Expand All @@ -16,7 +16,7 @@ hashmap["abc"] = 456
print(hashmap)

while true {
key = input("Enter key: ")
var key = input("Enter key: ")
if key == "exit" {break}
print(hashmap[key])
}
Expand Down
48 changes: 0 additions & 48 deletions examples/import_test.rn

This file was deleted.

16 changes: 14 additions & 2 deletions examples/io-test.rn
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,17 @@ print(str_val)
var password = io.Input.get_password("Enter a password: ")
print(password)

var val = input("Enter a value: ")
io.Output.write(val, sep="\n")
var val = null
var vals = []
print("Type 'exit' to stop.")

while val != "exit" {
val = input("Enter a value: ")
arr_append(vals, val)
}

print("unpacking is not implemented yet.")
io.Output.write(vals, sep="\n")

print("after unpacking, the result will be like this.")
io.Output.write("dsf", "sdf", "sdf", "sdf", "sdf", "exit", sep="\n")
6 changes: 3 additions & 3 deletions examples/json_testing.rn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
f = File("examples/posts.json", "r")
var f = File("examples/posts.json", "r")

json = Json()
posts = json.loads(f.read())
var json = Json()
var posts = json.loads(f.read())
f.close()

assert arr_len(posts) == 100
Expand Down
14 changes: 8 additions & 6 deletions examples/loops.rn
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ for i in [1, 2, 3, 4, 5] {
print(i)
}

#! Comment starts from here
for i in [1, 2, 3, 4, 5] {
if i == 3 {
break
break # it is exiting the program; not just the loop it self.
}
print(i)
}

!#

# While loop
#!
while i < 10 {
print(i)
i = i + 1

var j = 11
while j < 15 {
print(j)
j += 1
}
Loading

0 comments on commit b69126f

Please sign in to comment.