mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[Docs] error: 'index' does not implement the '__call__' method

Open a62690705 opened this issue 9 months ago • 7 comments

Where is the problem?

https://docs.modular.com/mojo/stdlib/collections/optional

What can we do better?

from collections.optional import Optional


def main():
    var a = Optional(1)
    var b = Optional[Int](None)
    if a:
        print(a.value())  # prints 1
    if b:  # b is False, so no print
        print(b.value())
    var c = a.or_else(2)
    var d = b.or_else(2)
    print(c.value())  # prints 1
    print(d.value())  # prints 2


Output

Compile error:

/source/prog.mojo:14:18: error: 'index' does not implement the '__call__' method
    print(c.value())  # prints 1
                 ^
/source/prog.mojo:15:18: error: 'index' does not implement the '__call__' method
    print(d.value())  # prints 2
                 ^
mojo: error: failed to parse the provided Mojo

Anything else?

No response

a62690705 avatar Apr 28 '24 13:04 a62690705

Optional.or_else(value) gives a T back now instead of an Optional[T]. So the prints should just be print(c) and print(d) rather than print(c.value() and print(d.value()).

Any interest in fixing the doc-strings in the code here? Soon we'll have doc-tests to avoid regressions like this in the future.

JoeLoser avatar Apr 28 '24 13:04 JoeLoser

When will it be released mojo 24.3.0 ?

When you say "it", do you mean the doc-string fix? It's still broken/incorrect on the nightly branch. If we fix it there, I'm happy to have it be cherry-picked into the upcoming 24.3.0 branch which will be released soon.

JoeLoser avatar Apr 28 '24 13:04 JoeLoser

I agree. We're actively working on that if you check out our roadmap and recent commits.

JoeLoser avatar Apr 28 '24 13:04 JoeLoser