Python utilities almost never check types

I passed several tests written in Java using JUnit, and I could not help but notice the emphasis placed on checking the "type" of objects. This is something I've never seen in Python test suites.

Java, statically typed, and Python dynamically typed, shouldn't it be the other way around?

+3
source share
3 answers

In dynamically typed languages, developers often follow the principle of duck typing - "if it looks like a duck and walks like a duck, it's a duck." While an object does what all tests require, does it really matter which object it is? A duck is typing.

+15
source

Python unit tests check types. All time. In fact, this is the only thing they do.

Python duck. Duck print means that the type of an object is determined by its behavior. Unit tests verify behavior. Ergo, they test types.

+5
source
0
source

Source: https://habr.com/ru/post/1769773/


All Articles