mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 16:06:39 +03:00
Changed *args parameter to be typed as Tuple rather than List, as per the python spec.
This commit is contained in:
parent
3dc47f15ba
commit
f6ebcd9243
@ -5784,10 +5784,10 @@ export function createTypeEvaluator(importLookup: ImportLookup): TypeEvaluator {
|
||||
}
|
||||
|
||||
case ParameterCategory.VarArgList: {
|
||||
const listType = getBuiltInType(node, 'List');
|
||||
|
||||
if (listType.category === TypeCategory.Class) {
|
||||
return ObjectType.create(ClassType.cloneForSpecialization(listType, [type]));
|
||||
// Create a Tuple[X, ...] type.
|
||||
const tupleType = getTypingType(node, 'Tuple');
|
||||
if (tupleType && tupleType.category === TypeCategory.Class) {
|
||||
return ObjectType.create(ClassType.cloneForSpecialization(tupleType, [type, AnyType.create(true)]));
|
||||
}
|
||||
|
||||
return UnknownType.create();
|
||||
|
@ -234,6 +234,12 @@ test('Function4', () => {
|
||||
validateResults(analysisResults, 0);
|
||||
});
|
||||
|
||||
test('Function5', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['function5.py']);
|
||||
|
||||
validateResults(analysisResults, 0);
|
||||
});
|
||||
|
||||
test('Annotations1', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['annotations1.py']);
|
||||
|
||||
|
12
server/src/tests/samples/function5.py
Normal file
12
server/src/tests/samples/function5.py
Normal file
@ -0,0 +1,12 @@
|
||||
# This sample tests that args and kwargs parameters are
|
||||
# properly typed.
|
||||
|
||||
from typing import Tuple, Dict, List
|
||||
|
||||
def function_with_args(*args: str) -> Tuple[str, ...]:
|
||||
return args
|
||||
|
||||
def function_with_kwargs(**kwargs: List[str]) -> Dict[str, List[str]]:
|
||||
return kwargs
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user