Skip to content
Discussion options

You must be logged in to vote

Yes, it is valid to treat a type as a callable. The callable signature is derived from the constructor of the class (either __new__ or __init__ or a combination of both).

I don't see a better way of doing this. The challenge is that your code assumes that the constructor accepts a bunch of parameters but can also be called with no arguments (because all of the parameters have defaults). There's no way to express that constraint in the type system, so the type checker doesn't know that you're making this assumption.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@FindDefinition
Comment options

@FindDefinition
Comment options

Answer selected by FindDefinition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants