Skip to content

Commit c1995e4

Browse files
committed
Always respect return type for class statements
1 parent 016cb16 commit c1995e4

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

docs/spec/constructors.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,17 @@ Keyword arguments in a direct metaclass call (such as the last two calls in the
667667
example above) require no special handling: they are validated as part of
668668
evaluating the call using the standard constructor call rules.
669669

670-
Regardless of the evaluated return type of the implied metaclass call, a
671-
:keyword:`class` statement defines a class, and type checkers should evaluate the
672-
type of the bound name accordingly (``type[MyClass1]`` in the example above).
673-
The implied metaclass call is evaluated only for the purpose of validating
674-
its arguments.
670+
Type checkers should honor the evaluated retunr type of the implied metaclass call,
671+
even if the evaluated type isn't a class::
672+
673+
class Meta(type):
674+
def __new__(cls, *args: object, **kwargs: obect) -> int:
675+
return 1
676+
677+
class MyClass6(metaclass=Meta):
678+
pass
679+
680+
assert_type(MyClass6, int)
675681

676682
Type checkers may validate the implied call to :attr:`!__prepare__`:
677683

0 commit comments

Comments
 (0)