mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 16:06:39 +03:00
Implemented unit test for NewType.
This commit is contained in:
parent
b7e37f12a9
commit
249dfa556d
18
server/src/tests/samples/newType1.py
Normal file
18
server/src/tests/samples/newType1.py
Normal file
@ -0,0 +1,18 @@
|
||||
# This sample tests the type handler's handling of the
|
||||
# built-in NewType function.
|
||||
|
||||
from typing import NewType
|
||||
|
||||
MyString = NewType('MyString', str)
|
||||
|
||||
def must_take_string(p1: str): pass
|
||||
|
||||
must_take_string(MyString('hello'))
|
||||
|
||||
def must_take_my_string(p1: MyString): pass
|
||||
|
||||
must_take_my_string(MyString('hello'))
|
||||
|
||||
# This should generate an error because 'hello'
|
||||
# isn't a valid MyString.
|
||||
must_take_my_string('hello')
|
@ -481,3 +481,10 @@ test('Super1', () => {
|
||||
|
||||
validateResults(analysisResults, 4);
|
||||
});
|
||||
|
||||
test('NewType1', () => {
|
||||
let analysisResults = TestUtils.typeAnalyzeSampleFiles(['newType1.py']);
|
||||
|
||||
validateResults(analysisResults, 1);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user