Closed Vardan2009 closed 4 months ago
How this will work with user defined objects?
Didn't think of that. I think users can define a custom__help_repr__
function in their classes to return a string
Can we dynamically generate the help from object? Example:
class AClass {
"AClass a simple OOP class."
fun __contructor__(num1) {
"The constructor"
this.num1 = num1
}
fun squre() {
# some hidden logics
return this.num1 ^ 2
}
fun add(n1, n2) {
# some hidden logics
return n1 + n2
}
}
Output
Help on int object:
class AClass()
|
| AClass a simple OOP class.
|
| a = AClass()
|
| null
|
| Methods defined here:
|
| squre()
| return this.num1 ^ 2
|
| add(n1, n2)
| return n1 + n2
|
Here in this example, help(obj)
will generate documentation like this format for builtin classes and user defined classes. We need to manage this or similar syntax.
Can we dynamically generate the help from object?
Is there a way to get all the methods and what they return dynamically?
Can we dynamically generate the help from object?
Is there a way to get all the methods and what they return dynamically?
Not exists till now?
So when defining a method in a class, it can also store that info somewhere, that might also help making the dir
function later
So when defining a method in a class, it can also store that info somewhere, that might also help making the
dir
function later
Yeah, you can create like that.
What do you think @angelcaru ?
I'm currently working on it, here is the result so far
Help on object Test:
class Test
| local_value = "value"
| fun __constructor__()
| returns something
|
| fun test(test,s)
| returns something
How can I check what the function returns if this is a dynamic typed language? Maybe we can put something else there, like a description for the method?
How can I check what the function returns if this is a dynamic typed language? Maybe we can put something else there, like a description for the method?
Showing description in return? Okay, fine for now.
how should the descriptions be written? Maybe a local variable in each function like:
fun test(test,s){
__desc = "Description for method test"
# Do something
}
Maybe a built-in function? Like:
fun test(test, s) {
# Do something
}
set_doc(test, "Description for method test")
Because I don't see how you would get the value for a __desc
variable without actually running the function
Oh... right
I think we can do it like Python. In the first line, if we have a string, then set it to description else put empty.
I think I got it working, here Input
class Test
{
fun __constructor__(){
}
fun test(test,s){
"Description for method test"
print("tesst")
}
}
help(Test())
Output
Help on object Test:
class Test
| fun __constructor__()
| [No Description]
|
| fun test(test,s)
| Description for method test
|
This will be like print(help(Test))
or print(help(Test()))
it will be just help(Test())
, and yes, it always has to get the instance to the class, not the class itself
it always has to get the instance to the class, not the class itself
That seems inconvenient. What if the constructor has arguments?
Yeah... I will try to get it working to accept both instances and classes
It should also work on standalone functions. Right now it only works on classes
So, something like this?
Help on function test
| fun test(args)
| desc
A new thing. If I want to get the output from help()
it returns the object. But, it should return null
.
fun some() -> null
a = help(some)
print(a) # <function some>
Little spacing will make this look pretty.
Help on object Test:
class Test
| property1 = "Hello, World!"
| fun __constructor__()
| [No Description]
| fun func1(arg1, arg2 = true)
| Description for func1
| fun func2(arg1 = null)
| Description for func2
| fun no_description()
| [No Description]
Help on object Test:
class Test
| property1 = "Hello, World!"
| fun __constructor__()
| [No Description]
| fun func1(arg1, arg2 = true)
| Description for func1
| fun func2(arg1 = null)
| Description for func2
| fun no_description()
| [No Description]
Help on function standalone
| fun standalone(arg1, arg2 = true)
| This is a standalone function
Previous output was nice.
Is this good?
Help on object Test:
class Test
| property1 = "Hello, World!"
|
| fun __constructor__()
| [No Description]
|
| fun func1(arg1, arg2)
| Description for func1
|
| fun func2(arg1)
| Description for func2
|
| fun no_description()
| [No Description]
|
Help on object Test:
class Test
| property1 = "Hello, World!"
|
| fun __constructor__()
| [No Description]
|
| fun func1(arg1, arg2)
| Description for func1
|
| fun func2(arg1)
| Description for func2
|
| fun no_description()
| [No Description]
|
Help on function standalone:
| fun standalone(arg1, arg2)
| This is a standalone function
Add spacing in also property. Example:
Help on object Test:
class Test
|
| property1 = "Hello, World!"
|
| fun __constructor__()
| [No Description]
|
| fun func1(arg1, arg2)
| Description for func1
|
| fun func2(arg1)
| Description for func2
|
| fun no_description()
| [No Description]
|
Help on object Test:
class Test
|
| property1 = "Hello, World!"
|
| fun __constructor__()
| [No Description]
|
| fun func1(arg1, arg2)
| Description for func1
|
| fun func2(arg1)
| Description for func2
|
| fun no_description()
| [No Description]
|
It is running the method or class to get its inner string!! This is now expected.
?
?
Check this. It is running the Test class to get it's inner descriptions.
class Test
{
property1 = "Hello, World!"
print(property1)
val = 324 + true
fun __constructor__()
{
}
fun func1(arg1, arg2=true)
{
"Description for func1"
}
fun func2(arg1=null)
{
"Description for func2"
return true
}
fun no_description() {
return null
}
}
help(Test)
No it's not? It's running the Test class to create the class. That's how it works
The descriptions get collected during the parsing. After the LBRACE, when it encounters a string, it sets it as it's description, then continues the parsing.
help()
displays help info for each data typePart of #8