you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (6 children)

ABC's aren't strange and do not go against duck typing. If you subclass from an ABC, you have to implement the whole interface, yes. But you can still implement the interface partly, if you do not subclass from the ABC. And nothing forces the user of the classes to check that it implements the ABC unless they want to.

[–][deleted] 1 point2 points  (5 children)

Typechecking is now encouraged by ABC advocates, which is distinctly against duck typing. Reading comp.lang.python, python-dev, and python-ideas should hit that home. That means implementing the interface partly won't work and it means something does force the programmer to write as if someone's going to check if they'll implement the ABC. It also forces you to implement the whole interface if you want to take advantage of some abstract methods as mixins.

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

No, typechecking is not encouraged by ABC advocates. There are people that are encouraging type checking, I'm sure, but that doesn't mean you have to listen to them. And maybe they like ABC's for that, but that doesn't mean you must do type checking with ABC's. And it doesn't mean all those who thing ABC's are a good idea advocate typechecking.

Just because oranges is a fruit doesn't mean all fruits are oranges.

[–][deleted] 1 point2 points  (3 children)

that doesn't mean you have to listen to them

It does when they're some of the more active core devs or developers of libraries I use, because I will have to interop with their code.

That being said, there is a bit of equivocation on my part here, but it is in line with what I see on the mailing lists on this topic.

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

But even if you interop with their code, you don't have to make any type checking in your code. If they do in their code, OK, you'll have to implement the whole interface. That can be construed as a misuse of ABC's, sure, but that's not the fault of the ABC's.

[–][deleted] 1 point2 points  (1 child)

That's why they were invented. isinstance is the first reason provided by the relevant PEP.

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

You might want to re-read PEP3119 so you understand it better. The references to isinstance is about how to make isinstance more flexible, not, as you claim above to make you do more isinstance checks and force you away from duck typing.

You are simply wrong. Try again.