forked from microsoft/pyright
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed a bug that results in incorrect type evaluation behaviors when …
…a class has a custom metaclass with a `__call__` method and a `__new__` or `__init__` method that provides a different bidirectional type inference context for parameters. This addresses microsoft#9067. (microsoft#9071)
- Loading branch information
Showing
3 changed files
with
52 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/pyright-internal/src/tests/samples/constructor32.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# This sample tests the case where a metaclass __call__ method is present | ||
# and supplies a different bidirectional type inference context than | ||
# the __new__ or __init__ methods. | ||
|
||
from typing import TypedDict | ||
|
||
|
||
class TD1(TypedDict): | ||
x: int | ||
|
||
|
||
class AMeta(type): | ||
def __call__(cls, *args, **kwargs): | ||
super().__call__(*args, **kwargs) | ||
|
||
|
||
class A(metaclass=AMeta): | ||
def __init__(self, params: TD1): | ||
pass | ||
|
||
|
||
A({"x": 42}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters