python-sfml icon indicating copy to clipboard operation
python-sfml copied to clipboard

Fused type or not

Open intjelic opened this issue 13 years ago • 0 comments

I don't know what the best code to use is.

I have a function which can take either a Position or a Size. What piece of code should I write ?

What's the impact on performances ?

def function(object pos_size):
if type(pos_size) is Position:
cfunction((<Position>pos_size).thisptr)
else:
cfunction((<Size>pos_size).thisptr)

OR

ctypedef fused pos_or_size:
Position
Size

def function(pos_or_size foo)
if pos_or_size is Position:
cfunction((<Position>foo).thisptr)
else:
cfunction((<Size>foo).thisptr)

intjelic avatar Dec 30 '12 07:12 intjelic