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
no error on invalid call to __init_subclass__ #3447
classFoo:
def__init_subclass__(cls, asdf: int) ->None:
passclassBar(Foo, asdf=1): ...
classBaz(Foo, asdf=""): ... # no errorclassQux(Foo): ... # no error
it looks like pyrefly doesn't support __init_subclass__ at all. bad-typed-dict special-cases it for TypedDict, but ideally that rule should be removed and replaced with a more general rule that checks __init_subclass__ calls on any class
Thanks for the report, @DetachHead! Confirmed on HEAD that pyrefly produces 0 errors for all three cases. Pyrefly currently doesn't validate kwargs on class statements against the parent's init_subclass signature at all. No type checking, no missing-argument detection. The class Qux(Foo) case is particularly important since it produces a TypeError at import time in Python.
The existing bad-typed-dict special case for TypedDict's total kwarg would ideally be generalized into a proper init_subclass validation rule for all classes.
@stroxler can we extend the implementation of TypedDict's kwarg handling to Pyrefly's init subclass kwarg handling as well ?
This issue has someone assigned, but has not had recent activity for more than 2 weeks.
If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.
Activity
NathanTempest commentedon May 18, 2026
Thanks for the report, @DetachHead! Confirmed on HEAD that pyrefly produces 0 errors for all three cases. Pyrefly currently doesn't validate kwargs on class statements against the parent's init_subclass signature at all. No type checking, no missing-argument detection. The class Qux(Foo) case is particularly important since it produces a TypeError at import time in Python.
The existing bad-typed-dict special case for TypedDict's total kwarg would ideally be generalized into a proper init_subclass validation rule for all classes.
@stroxler can we extend the implementation of TypedDict's kwarg handling to Pyrefly's init subclass kwarg handling as well ?
DetachHead commentedon Jun 11, 2026
also should be a check to ensure that
__init_subclass__is callable:https://docs.astral.sh/ty/reference/rules/#non-callable-init-subclass
github-actions commentedon Jun 26, 2026
This issue has someone assigned, but has not had recent activity for more than 2 weeks.
If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.
Thank you for your contributions!
fix no error on invalid call to `__init_subclass__` #3447 (#3468)
rchen152 commentedon Aug 11, 2026
I'll work on a fix for the remaining false negative in #3447 (comment).
Detect when `__init_subclass__` is not callable
fix no error on invalid call to `__init_subclass__` pyrefly-org#3447 (p…