Fixed bug that resulted in false positive error when second argument to NewType call contained a Type object.

This commit is contained in:
Eric Traut 2021-06-07 13:36:14 -07:00
parent ec478e68de
commit 029eb2c869
2 changed files with 12 additions and 2 deletions

View File

@ -9176,7 +9176,7 @@ export function createTypeEvaluator(
}
if (argList.length >= 2) {
const baseClass = getTypeForArgumentExpectingType(argList[1]);
const baseClass = transformTypeObjectToClass(getTypeForArgumentExpectingType(argList[1]));
if (isClass(baseClass)) {
if (ClassType.isProtocolClass(baseClass)) {

View File

@ -1,7 +1,7 @@
# This sample tests the type handler's handling of the
# built-in NewType function.
from typing import NewType
from typing import NewType, Type, TypeVar
MyString = NewType("MyString", str)
@ -22,3 +22,13 @@ must_take_my_string(MyString("hello"))
# This should generate an error because 'hello'
# isn't a valid MyString.
must_take_my_string("hello")
_T = TypeVar("_T")
def func1(x: Type[_T]) -> Type[_T]:
return x
MyString2 = NewType("MyString2", func1(str))