Is there I way that I can annotate a function to ensure that an object being passed into the function has a certain method or attribute, but where I don't care about its actual type?
Pycharm internally uses a syntax that looks like {b}
to indicate what methods/attributes it's inferred are required for the object, but that doesn't appear to be valid Python syntax:
def func(a: {b}): # Error
a.b = 1
Is there a way to get the type checker to assist in duck typing, where I only care what methods/attributes the object has, not what the type of the objects are, and where I can't modify the types I want to check for?