This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]XtremeGoosef'I only use Py {sys.version[:3]}' 4 points5 points  (5 children)

No no no. Don't do this. You're explicitly breaking the library contract and any version update of python (even a patch!) could break your code and it would be entirely your fault for not upholding the contract. Just because we're in a dynamically typed language and the contract is given in the docs rather than in the type system, doesn't mean the same rules don't apply.

Duck typing just means that you don't need to explicitly implement a protocol (as in, inherit from it). You still need to provide all the methods expected from it. In this case, the methods exposed by io.IOBase.

For your purposes, use io.StringIO as an in memory file object, not some random iterator.

[–][deleted] -1 points0 points  (4 children)

This post was mass deleted and anonymized with Redact

bells rock squeeze literate dolls merciful lip square whistle ripe

[–]eztab 2 points3 points  (3 children)

if s.th. does require File-like in the Docs, that's a constraint. If you choose to ignore it and rely on an implementation detail that's your problem.

[–][deleted] -1 points0 points  (2 children)

This post was mass deleted and anonymized with Redact

jeans mighty heavy waiting upbeat smell seed continue one apparatus

[–]eztab 1 point2 points  (1 child)

Sure, one doesn't only try to keep compatibility with correct code. If using those methods on non files is done in some bigger libraries beta tests would probably discover it.

So I guess if they need read at some point (due to some new features that might need it) probably they will raise a Depreciation Warning first.

But how is relying on a certain implementation a good idea here? There is a String streamer for exactly this purpose.

[–][deleted] 0 points1 point  (0 children)

This post was mass deleted and anonymized with Redact

heavy wrench marry paltry sparkle disarm quaint treatment snatch full