File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed
src/test/java/org/sonar/python/types Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -527,6 +527,15 @@ public void typeshed_private_modules_should_not_affect_fqn() {
527
527
assertThat (socket .superClasses ()).extracting (Symbol ::fullyQualifiedName ).containsExactly ("object" );
528
528
}
529
529
530
+ @ Test
531
+ public void overloaded_function_alias_has_function_annotated_type () {
532
+ Map <String , Symbol > gettextModule = symbolsForModule ("gettext" );
533
+ Symbol translation = gettextModule .get ("translation" );
534
+ Symbol catalog = gettextModule .get ("Catalog" );
535
+ assertThat (translation .kind ()).isEqualTo (Kind .AMBIGUOUS );
536
+ assertThat (catalog .annotatedTypeName ()).isEqualTo ("function" );
537
+ }
538
+
530
539
@ Test
531
540
public void stubFilesSymbols_third_party_symbols_should_not_be_null () {
532
541
// six modules contain ambiguous symbols that only contain class symbols
Original file line number Diff line number Diff line change @@ -135,6 +135,12 @@ def __init__(self, _type: mpt.Type):
135
135
self .kind = TypeKind .TYPED_DICT
136
136
# TODO: check in items for key/type mapping
137
137
self .pretty_printed_name = "TypedDict"
138
+ elif isinstance (_type , mpt .Overloaded ):
139
+ self .kind = TypeKind .CALLABLE
140
+ fallback = TypeDescriptor (_type .fallback )
141
+ self .fully_qualified_name = fallback .fully_qualified_name
142
+ self .args .append (fallback )
143
+ self .pretty_printed_name = f"CallableType[{ fallback .pretty_printed_name } ]"
138
144
else :
139
145
# this can happen when there is a var symbol assigned to an overload symbol
140
146
self .is_unknown = True
Original file line number Diff line number Diff line change 21
21
from unittest .mock import Mock
22
22
23
23
from serializer import symbols , symbols_merger
24
- from serializer .symbols import MergedModuleSymbol
24
+ from serializer .symbols import MergedModuleSymbol , TypeKind
25
25
26
26
27
27
def test_build_multiple_python_version (typeshed_stdlib ):
@@ -235,8 +235,9 @@ def test_actual_module_merge(fake_module_36_38):
235
235
alias = all_vars ['fakemodule.alias' ]
236
236
assert len (alias ) == 1
237
237
alias_symbol = alias [0 ].var_symbol
238
- assert alias_symbol .type .fully_qualified_name is None
239
- assert alias_symbol .type .is_unknown is True
238
+ assert alias_symbol .type .fully_qualified_name == "builtins.function"
239
+ assert alias_symbol .type .kind == TypeKind .CALLABLE
240
+ assert alias_symbol .type .pretty_printed_name == "CallableType[builtins.function]"
240
241
241
242
imported_sys = all_vars ['sys' ]
242
243
assert len (imported_sys ) == 1
You can’t perform that action at this time.
0 commit comments