from thinglang.lexer.symbols.base import LexicalIdentifier


class ThingInstance(object):

    def __init__(self, cls):
        self.cls = cls
        self.methods = {
            x.name: x for x in self.cls.children
        }
        self.members = {}

    def __contains__(self, item):
        return item in self.members or item in self.methods

    def __getitem__(self, item):
        return self.members.get(item) or self.methods.get(item)

    def __str__(self):
        return f'Thing<{self.cls}>(members={self.members}, methods={self.methods})'
from thinglang.lexer.symbols.base import LexicalIdentifier


class ThingInstance(object):

    def __init__(self, cls):
        self.cls = cls
        self.methods = {
            x.name: x for x in self.cls.children
        }
        self.members = {}

    def __contains__(self, item):
        return item in self.members or item in self.methods

    def __getitem__(self, item):
        return self.members.get(item) if item in self.members else self.methods[item]

    def __str__(self):
        return f'Thing<{self.cls}>(members={self.members}, methods={self.methods})'
Fix bug in ThingInstace __setitem__
Fix bug in ThingInstace __setitem__

  from thinglang.lexer.symbols.base import LexicalIdentifier
  
  
  class ThingInstance(object):
  
      def __init__(self, cls):
          self.cls = cls
          self.methods = {
              x.name: x for x in self.cls.children
          }
          self.members = {}
  
      def __contains__(self, item):
          return item in self.members or item in self.methods
  
      def __getitem__(self, item):
-         return self.members.get(item) or self.methods.get(item)
+         return self.members.get(item) if item in self.members else self.methods[item]
  
      def __str__(self):
          return f'Thing<{self.cls}>(members={self.members}, methods={self.methods})'
Fix bug in ThingInstace __setitem__
## Code Before:
from thinglang.lexer.symbols.base import LexicalIdentifier


class ThingInstance(object):

    def __init__(self, cls):
        self.cls = cls
        self.methods = {
            x.name: x for x in self.cls.children
        }
        self.members = {}

    def __contains__(self, item):
        return item in self.members or item in self.methods

    def __getitem__(self, item):
        return self.members.get(item) or self.methods.get(item)

    def __str__(self):
        return f'Thing<{self.cls}>(members={self.members}, methods={self.methods})'
## Instruction:
Fix bug in ThingInstace __setitem__
## Code After:
from thinglang.lexer.symbols.base import LexicalIdentifier


class ThingInstance(object):

    def __init__(self, cls):
        self.cls = cls
        self.methods = {
            x.name: x for x in self.cls.children
        }
        self.members = {}

    def __contains__(self, item):
        return item in self.members or item in self.methods

    def __getitem__(self, item):
        return self.members.get(item) if item in self.members else self.methods[item]

    def __str__(self):
        return f'Thing<{self.cls}>(members={self.members}, methods={self.methods})'