FakeFileWrapper doesn't inherit from io.IOBase #855
Replies: 10 comments
-
Do you need that it actually inherits, or that it implements the |
Beta Was this translation helpful? Give feedback.
-
I do actually need it to inherit. It's a bit hard to explain, but I have a whole bunch of functions that rely on the file objects' MRO to work correctly. The functions work differently depending on whether the file object inherits from Here's the MRO of a file opened in text mode (
A file opened with
And
|
Beta Was this translation helpful? Give feedback.
-
Hm, I have thought about this a bit, and I'm afraid that this is not something we are able to do without a major restructuring. We aim at emulating the functionality (e.g. it shall be possible to call every method as on the original object), but not on inheritance compatibility, which is an implementation detail that may change. Generally, I do not rely on MRO checks, because it is common in Python to emulate functionality by implementing interfaces instead of inheriting from the same base class (there are the |
Beta Was this translation helpful? Give feedback.
-
I think you're wrong about the MRO being an implementation detail. I found this in the
|
Beta Was this translation helpful? Give feedback.
-
Well, you are right about the docs, though that doesn't change the fact that this will not be an easy change. I have been struggling with different IO behavior in different OSes and with different Python versions, and restructuring the code respectively is something I'm not looking forward to... so I may think about this, but don't expect something soon - sorry. |
Beta Was this translation helpful? Give feedback.
-
No problem. I'll just use real files for my tests, then. |
Beta Was this translation helpful? Give feedback.
-
Just for reference - this is only relevant for Python 3. |
Beta Was this translation helpful? Give feedback.
-
I have played around a bit with this, and didn't find a way to make this really working without a major rewrite. I will add a respective note to the documentation (limitations section) and close this issue. |
Beta Was this translation helpful? Give feedback.
-
Running your tests that use the real file system inside a Docker container would give you the ephemerality of pyfakefs plus the exact implementation details like MRO. Free software is so refreshing--no penalty for recommending the competition. |
Beta Was this translation helpful? Give feedback.
-
I would call it alternative, not competition 😛 Actually, I had been thinking about documenting alternatives with pros and cons, after the limitations paragraph. Docker is certainly the mostly used alternative today, at least under Linux. Maybe I'll add this before the next release... I added a |
Beta Was this translation helpful? Give feedback.
-
Regular file objects inherit from
io.IOBase
, but the fake variant doesn't. Here's a test case that fails if thefs
fixture is used, but passes otherwise:I'm working on a file-object related library, so I really need this to work correctly.
Beta Was this translation helpful? Give feedback.
All reactions