Skip to content

What is the proper way to give type hint for dynamic attributes of decorated classes? #1917

Answered by TeamSpen210
McDic asked this question in Q&A
Discussion options

You must be logged in to vote

There isn’t a way to define this right now. (intersections could do it but that’s a massive new feature.), One solution would be to make fresh_copy a function, not a method. You’d have to type-ignore inside the function, but callers would type correctly. Except that it’d be possible to pass undecorated classes, who would fail at runtime.

Have you considered just defining __copy__ methods, and then using copy.copy? You’d have no issues then.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@McDic
Comment options

Answer selected by McDic
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