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

Mypy strict passing. #169

Merged
merged 32 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
71999cd
fix: module name and var declaration.
Almas-Ali Jul 20, 2024
29497da
fix: module name and replaced arr_len() to len() builtin.
Almas-Ali Jul 20, 2024
cd8ae2d
fix: replace arr_find() to slice operator and __len__() now based on …
Almas-Ali Jul 20, 2024
d8e6bcf
fix: removed Test() class.
Almas-Ali Jul 20, 2024
9fbd406
fix: var declaration.
Almas-Ali Jul 20, 2024
df7673f
fix: updated module name.
Almas-Ali Jul 20, 2024
312d114
fix: var declaration.
Almas-Ali Jul 20, 2024
87f1e9f
fix: replace arr_len() to len().
Almas-Ali Jul 20, 2024
0f79bf8
fix: File().readline() crash issue.
Almas-Ali Jul 20, 2024
8574f99
fix: var declaration and names.
Almas-Ali Jul 20, 2024
dc8652e
fix: removed deprecated codes.
Almas-Ali Jul 20, 2024
99b3733
fix: var declaration.
Almas-Ali Jul 20, 2024
2d8e21d
fix: removed deprecated codes.
Almas-Ali Jul 20, 2024
3ae4077
fix: String.split() method crashing issue and argument passing.
Almas-Ali Jul 20, 2024
2c8d5cd
refactor: updated example.
Almas-Ali Jul 20, 2024
1e483a3
fix: var declaration.
Almas-Ali Jul 20, 2024
a1055b4
fix: uncommented while and commented issue on for.
Almas-Ali Jul 20, 2024
31b2787
fix: failing issues.
Almas-Ali Jul 21, 2024
49e1adf
refactor: ruff format
Almas-Ali Jul 21, 2024
bab8549
fix: var declaration.
Almas-Ali Jul 21, 2024
4daec1d
fix: file not found issue from shell.
Almas-Ali Jul 21, 2024
23ca7a8
fixed: operators bug has been resolved.
Almas-Ali Jul 21, 2024
394383e
fix: removed deprecated codes.
Almas-Ali Jul 21, 2024
8bda104
fix: var declaration.
Almas-Ali Jul 21, 2024
c310b51
refactor: updated help text.
Almas-Ali Jul 21, 2024
042145f
fix: var declaration.
Almas-Ali Jul 21, 2024
3331468
fix: example to display properly.
Almas-Ali Jul 21, 2024
0a6598c
fix: slicing example.
Almas-Ali Jul 21, 2024
c956d91
fix: old syntax update.
Almas-Ali Jul 21, 2024
88918d0
fix: mypy --strict test passed.
Almas-Ali Jul 21, 2024
67c8404
fix: var declaration and module name update.
Almas-Ali Jul 21, 2024
c91e483
fixes: make format (ruff).
Almas-Ali Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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