[Python-bugs-list] [ python-Feature Requests-519230 ] hook method for 'is' operator

noreply@sourceforge.net noreply@sourceforge.net
Mon, 18 Feb 2002 09:51:02 -0800


Feature Requests item #519230, was opened at 2002-02-18 09:13
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=355470&aid=519230&group_id=5470

Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Dan Parisien (mathematician)
Assigned to: Nobody/Anonymous (nobody)
Summary: hook method for 'is' operator

Initial Comment:
Being able to overload the 'is' operator would lead 
to nicer more readable code:

# constant
Open = ("OPEN",)

# dummy class for my example
class File:
	id = 0
	def __init__(self, file=None):
		if file is not None:
			self.open(file)

	# overload 'is' operator
	def __is__(self, other):
		if id(self)==id(other): # default
			return 1
		elif other==("OPEN",) and self.id!=0:
			return 1
		return 0

	def open(self, file):
		self.id = open(file).fileno

f = File("myfile.txt")
if f is Open:
	print "File is open!"
else:
	print "File is not open"

'is not' could just test __is__ and return 'not 
retval'




----------------------------------------------------------------------

>Comment By: Dan Parisien (mathematician)
Date: 2002-02-18 09:51

Message:
Logged In: YES 
user_id=118203

This is a duplicate entry. sf.net was timing out, so I 
submitted it twice. It seems that the first time it went 
through... oops!
see 
http://sourceforge.net/tracker/index.php?func=detail&aid=519227&group_id=5470&atid=355470



----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=355470&aid=519230&group_id=5470