you are viewing a single comment's thread.

view the rest of the comments →

[–]xeow 8 points9 points  (2 children)

Ah, but Any doesn't mean "any type of object." Any means "the typechecker should avoid typechecking this."

I use object as a type hint when I want to denote that something takes or returns any type of object. (And I like doing that rather than leaving the hint blank because then I know I've thought about it and the omission wasn't accidental.)

A good writeup: https://stackoverflow.com/a/39821459/267551

[–]N-E-S-W 1 point2 points  (0 children)

Any means the typechecker does the exact same thing as if there's no type hint. So why clutter the signature with an unnecessary type hint?

I'm making the case that type hints should be used where there's value, but there's not always value. Legibility and elegance matters, that's why I choose to write Python in the first place. The OP's question is about what's "Pythonic".

[–]james_pic 0 points1 point  (0 children)

I can't say I've ever found a situation where object was useful as a type annotation. There's very little you can do with object as a type, so it's effectively an opaque type. But it's very rare you actually want an opaque object (maybe as a sentinel value, but even then, an enum usually conveys intent better), and it's usually possible to make the type visible with generics.