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

noreply@sourceforge.net noreply@sourceforge.net
Mon, 18 Feb 2002 09:14:06 -0800


Feature Requests item #519227, was opened at 2002-02-18 09:12
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=355470&aid=519227&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'




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

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