A proposal for attribute lookup failures

MonkeeSage MonkeeSage at gmail.com
Mon Nov 19 00:02:01 CET 2007


Ps. Just for kicks, here is a simple ruby 1.8 mock-up of the proposal
(sorry for using ruby, but I don't know enough C to start hacking the
CPython backend; I think that a higher-level example is conceptually
clearer anyhow). Reference cycles are not detected in the example.

#!/usr/bin/ruby

class Object
  def method_missing(fun, *args)
    begin
      TOPLEVEL_BINDING.method(fun).call(self, *args)
    rescue
      raise(NoMethodError,
            %{undefined method `#{fun.to_s}' for "#{self}":String},
            [])
    end
  end
end

def myfun(s1, s2)
  s1 + s2
end

puts "foo".myfun("bar")
# -> foobar

puts 1.myfun(2)
# -> 3

puts "foo".nofun("baz")
# -> ./attr_fail.rb:10: undefined method `nofun' for "foo":String
(NoMethodError)



More information about the Python-list mailing list