Skip to content

Found a problem with the args of the Dictionary "items" function. #101

Description

@Sungmin-Joo

Current Results
in gpython

>>>> d_list = {'a' : 1, 'b' : 2}
>>>> for k, v in d_list.items("hi"):
>>>>     print(k,':',v)
a : 1
b : 2

in python

>>>> d_list = {'a' : 1, 'b' : 2}
>>>> for k, v in d_list.items("hi"):
>>>>     print(k,':',v)
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    for k, v in d_list.items("hi"):
TypeError: items() takes no arguments (1 given)

gpython/py/dict.go

Lines 30 to 39 in af17d7d

func init() {
StringDictType.Dict["items"] = MustNewMethod("items", func(self Object, args Tuple) (Object, error) {
sMap := self.(StringDict)
o := make([]Object, 0, len(sMap))
for k, v := range sMap {
o = append(o, Tuple{String(k), v})
}
return NewIterator(o), nil
}, 0, "items() -> list of D's (key, value) pairs, as 2-tuples")
}

I think we should add an error to this part of the code.

Activity

  1. Sungmin-Joo commented on Sep 29, 2019

    @Sungmin-Joo
    ContributorAuthor

    @Tim-St
    I found a mistake in the code I used in the issue.
    Please check again.

  2. Sungmin-Joo commented on Oct 1, 2019

    @Sungmin-Joo
    ContributorAuthor

    @Tim-St
    Ok.
    When I finish my ongoing Pull Request, I'll do this right away.

  3. added a commit that references this issue on Nov 18, 2019
    4c28217
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions