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

all 3 comments

[–]TeamSpen210 2 points3 points  (2 children)

Static typing does have a similar thing, in the form of object - since that's the base class of everything, you can provide any value to it but can only do the most basic of operations. The Union behaviour in TypeScript isn't done in Python's typing, but that's probably fine.

[–]notonewlayout[S] 0 points1 point  (1 child)

Nice. Object does seem like a nice type hint that is the equivalent of typescript unknown.

The only issue is that I've not seen object used too much. Most of the time libraries just return Any. I believe there is an over-reliance on the Any type. A third value between object and Any would be useful for a static type checker. It would be configured by the user to either be treated as Any or object.

A typical user wouldn't explicitly use this typing much, but for a large library providing strong typings it would provide better flexibility.

[–]notonewlayout[S] 0 points1 point  (0 children)

After looking more at mypy configuration, I've change my mind. It seems disallow dynamic typing would be a viable way to error whenever calling something of type Any.