Problem with recursion function calling to get part's source element using python

Hi all,
I want to make a function in python script that recursively calls itself until it reaches a element that is not a part, because sometimes the source element of a part is also a part. But my code is always returning the input.
I could(maybe) use a while loop but I am trying to better understand recursion and python.
Here is my code:

import sys
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import UIApplication
import RevitServices
from RevitServices.Persistence import DocumentManager

def GetParentRecursive(doc,elem):
    
    if type(elem) is Part:
        sElem = doc.GetElement(elem.GetSourceElementIds().get_item[0].HostElementId)
        return GetParentRecursive(doc,sElem)
    else:
        return elem
 


elem = IN[0]
doc = DocumentManager.Instance.CurrentDBDocument
result = GetParentRecursive(doc,elem)
OUT = result

image

Nevermind, I found out some errors with my code:
1- I forgot to unwrap the element.
2- My “if” statement was wrong. Coming from a C# background I was thinking that I could just check if is Part using the “is” statement.
3-I was using “get_item” to get the first item of list, which was wrong.
My bad.
This is the correct code if anyone wants:

import sys
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import UIApplication
import RevitServices
from RevitServices.Persistence import DocumentManager

def GetParentRecursive(doc,elem):
    
    if elem.Category.BuiltInCategory==BuiltInCategory.OST_Parts:
        elem = doc.GetElement(elem.GetSourceElementIds()[0].HostElementId)
        return GetParentRecursive(doc,elem)
    else:
        return elem

elem = UnwrapElement(IN[0])
doc = DocumentManager.Instance.CurrentDBDocument
result = GetParentRecursive(doc,elem)
OUT = result