Giter Site home page Giter Site logo

Comments (5)

ncw avatar ncw commented on May 13, 2024

The gpython print is fairly minimal at the moment and certainly needs improving.

I think this particular bug is caused by this line doing the argument parsing wrong (not sure exactly why).

err := py.ParseTupleAndKeywords(nil, kwargs, "|ssOO:print", kwlist, &sepObj, &endObj, &file, &flush)

from gpython.

Sungmin-Joo avatar Sungmin-Joo commented on May 13, 2024

@ncw
There is a temporary way to modify the builtin_print.
But I don't think it's the right way.

func builtin_print(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Object, error) {
    var (
        sepObj py.Object = py.String(" ")
        endObj py.Object = py.String("\n")
        file   py.Object = py.MustGetModule("sys").Globals["stdout"]
        flush  py.Object
    )
    kwlist := []string{"sep", "end", "file", "flush"}
    for _, kw := range kwlist {
        switch _, ok := kwargs[kw]; ok {
        case true:
            continue
        default:
            if kw == "sep" {
                kwargs[kw] = sepObj
            } else if kw == "end" {
                kwargs[kw] = endObj
            } else if kw == "file" {
                kwargs[kw] = file
            } else {
                kwargs[kw] = flush
            }
        }
    }
    err := py.ParseTupleAndKeywords(nil, kwargs, "|ssOO:print", kwlist, &sepObj, &endObj, &file, &flush)
    ...

from gpython.

ncw avatar ncw commented on May 13, 2024

py.ParseTupleAndKeywords should be doing that for us...

The bug must be in this bit of code I think... No time to investigate further right now - over to you to have a look!

gpython/py/args.go

Lines 444 to 453 in 8c361a8

for i, kw := range kwlist {
if value, ok := kwargs[kw]; ok {
if len(args) > i {
return ExceptionNewf(TypeError, "%s() got multiple values for argument '%s'", name, kw)
}
args = append(args, value)
} else if keywordOnly {
args = append(args, nil)
}
}

from gpython.

drew-512 avatar drew-512 commented on May 13, 2024

suggest @sbinet close -- fixed w/ #151

from gpython.

sbinet avatar sbinet commented on May 13, 2024

fixed w/ #151.

from gpython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.