In Python's pathlib module you can create a Path object from another Path and they will be equivalent:
p = Path('some/path')
p2 = Path(p)
p == p2
# True
I have a File class that I would like to implement this same behavior, where if I pass a File object to the File constructor, it will simply return the original object that was passed in. What is the correct way to do so? Do I need to override the __new__ method to achieve this?
p is p2will evaluate toFalse. they are equal but not identical. Although, one example of where you will see this behavior is with strings, i.e.str(some_str) is some_strhappens to be true in CPython.