How do I validate an implementation of python's IOBase?
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Meadow
--
Chapters
00:00 How Do I Validate An Implementation Of Python'S Iobase?
01:48 Accepted Answer Score 2
03:44 Thank you
--
Full question
https://stackoverflow.com/questions/3825...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #testing #io
#avk47
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Meadow
--
Chapters
00:00 How Do I Validate An Implementation Of Python'S Iobase?
01:48 Accepted Answer Score 2
03:44 Thank you
--
Full question
https://stackoverflow.com/questions/3825...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #testing #io
#avk47
ACCEPTED ANSWER
Score 2
Python docs are the only official, authoritative source containing promises/guarantees about the stock implementation's behaviour - there's just nothing else officially published. If something is not documented, it
doesn't existshould not be relied upon.- There's a unit test for the
iomodule,test_io.py, in the source repo (you can also choose to install the test suite with the interpreter). Do watch out for implementation-specific details depending on your answer in the next paragraph.- Also watch for details specific to the
ioimplementation of the base classes: as Andrea Corbellini noted, there is a spec for a base class and there is a spec for its derivative.
- Also watch for details specific to the
- There's a unit test for the
Some behaviour is implementation-specific and indeed differs between Python implementations (e.g. in IronPython,
sys.maxsizeis ridiculously large 'cuz there's no such mechanism in .NET and all strings are Unicode even though it implements Python 2).- The question here is: is your target compilance with specification or with a specific implementation? The answer depends on how much (and how well- (or rather, badly, i.e. unportably) written) code you want to be compatible with.
- Since we're talking about abstract classes here, there's no "specific implementation" really except the little default/non-abstract code in relevant entities. So the difference is rather small.
- The question here is: is your target compilance with specification or with a specific implementation? The answer depends on how much (and how well- (or rather, badly, i.e. unportably) written) code you want to be compatible with.
Now, there are indeed cases where the spec omits, or is vague on, some critical details (I've personally run into at least two cases in
ctypes). That's because it's written as a user's rather than implementor's guide.- There's nothing you can do here other than stick to the spec and fix things as you run into them. In vague cases, you can check the implementation but be sure to find out the rationale (what it is conceptually intended to do) to decide what is appropriate in your case. After all, if you're replacing an internal module, how can you know how much undocumented behaviour other internal modules rely upon?
- To Python devs' credit, the latter cases should be extremely rare as they do honor the loose coupling principle and strive to stick to the spec (where there is a spec) in inter-module interactions.
- There's nothing you can do here other than stick to the spec and fix things as you run into them. In vague cases, you can check the implementation but be sure to find out the rationale (what it is conceptually intended to do) to decide what is appropriate in your case. After all, if you're replacing an internal module, how can you know how much undocumented behaviour other internal modules rely upon?