Skip to content

Checking dict keys fails #58

Description

@kellrott

In standard python

>>> x={"hello" : "world"}
>>> "hello" in x
True

In gpython

>>> x={"hello" : "world"}
>>> "hello" in x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    FIXME line of source goes here
TypeError: "unsupported operand type(s) for iter: 'dict'"

Activity

  1. ncw commented on May 18, 2019

    @ncw
    Collaborator

    Implementing __iter__ for dict is very useful.

    However for in to be efficient we should be implementing __contains__

    gpython/py/sequence.go

    Lines 121 to 147 in 61059b4

    // SequenceContains returns True if obj is in seq
    func SequenceContains(seq, obj Object) (found bool, err error) {
    if I, ok := seq.(I__contains__); ok {
    result, err := I.M__contains__(obj)
    if err != nil {
    return false, err
    }
    return result == True, nil
    } else if result, ok, err := TypeCall1(seq, "__contains__", obj); ok {
    if err != nil {
    return false, err
    }
    return result == True, nil
    }
    var loopErr error
    err = Iterate(seq, func(item Object) bool {
    var eq Object
    eq, loopErr = Eq(item, obj)
    if loopErr != nil {
    return true
    }
    if eq == True {
    found = true
    return true
    }
    return false
    })

  2. drew-512 commented on Feb 16, 2022

    @drew-512
    Contributor

    suggest @sbinet close -- addressed in #65

  3. sbinet commented on Feb 22, 2022

    @sbinet
    Member

    fixed w/ #65 .

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