You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Would it be possible to broaden classmethod to accept ParamSpec when MyPy's support is better? #7689
Also, staticmethod is quite a lot easier than classmethod. staticmethod doesn't change the signature of the function it wraps, but classmethod does -- it requires Concatenate. It would be something like this:
@JelleZijlstra Yup, I just learned about that here. It's not too big a deal since it's very rare that you decorate class methods, but maybe after classmethod is broadened they might consider producing a classmethod[P, R, T] instead of a Callable[Concatenate[type[T], P], R].
Mypy 0.950 is now out, but sadly we still cannot use ParamSpec in classmethod or staticmethod due to python/mypy#12011. (abc.abstractclassmethod and abc.abstractstaticmethod inherit from classmethod and staticmethod respectively, so while that mypy issue is outstanding, we cannot make builtins.staticmethod or builtins.classmethod generic over a parameter specification without breaking those two classes.)
Activity
AlexWaygood commentedon Apr 26, 2022
This is on my to-do list for as soon as mypy 0.950 is released 🙂
JelleZijlstra commentedon Apr 26, 2022
Though I'm not sure how much of a difference this will make, considering how thoroughly type checkers special case classmethod (and staticmethod).
AlexWaygood commentedon Apr 26, 2022
Also,
staticmethodis quite a lot easier thanclassmethod.staticmethoddoesn't change the signature of the function it wraps, butclassmethoddoes -- it requiresConcatenate. It would be something like this:NeilGirdhar commentedon Apr 26, 2022
@JelleZijlstra Yup, I just learned about that here. It's not too big a deal since it's very rare that you decorate class methods, but maybe after
classmethodis broadened they might consider producing aclassmethod[P, R, T]instead of aCallable[Concatenate[type[T], P], R].AlexWaygood commentedon Apr 28, 2022
Mypy 0.950 is now out, but sadly we still cannot use
ParamSpecinclassmethodorstaticmethoddue to python/mypy#12011. (abc.abstractclassmethodandabc.abstractstaticmethodinherit fromclassmethodandstaticmethodrespectively, so while that mypy issue is outstanding, we cannot makebuiltins.staticmethodorbuiltins.classmethodgeneric over a parameter specification without breaking those two classes.)