Skip to content

Commit

Permalink
Fixed a bug where attributes with call expressions as type hint would…
Browse files Browse the repository at this point in the history
… get "Any" as type
  • Loading branch information
Masara committed Nov 27, 2023
1 parent 4bff2cb commit 8b44fe6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
5 changes: 4 additions & 1 deletion src/safeds_stubgen/api_analyzer/_ast_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,10 @@ def _create_attribute(
raise TypeError("Attribute has an unexpected type.")

type_ = None
if attribute_type is not None:
# Ignore types that are special mypy any types
if (attribute_type is not None and
not (isinstance(attribute_type, mp_types.AnyType) and attribute_type.type_of_any in
{mp_types.TypeOfAny.unannotated, mp_types.TypeOfAny.from_error})):
type_ = mypy_type_to_abstract_type(attribute_type, unanalyzed_type)

# Get docstring
Expand Down
36 changes: 16 additions & 20 deletions tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@
'is_static': True,
'is_type_inferred': False,
'name': 'callexpr_attr',
'type': dict({
'kind': 'NamedType',
'name': 'Any',
'qname': '',
}),
'type': None,
}),
dict({
'docstring': dict({
Expand Down Expand Up @@ -4243,48 +4239,48 @@
'types': list([
dict({
'kind': 'NamedType',
'name': 'int',
'name': 'float',
'qname': '',
}),
dict({
'kind': 'NamedType',
'name': 'InferMe',
'qname': 'tests.data.test_package.infer_types_module.InferMe',
'name': 'InferMyTypes',
'qname': 'tests.data.test_package.infer_types_module.InferMyTypes',
}),
dict({
'kind': 'NamedType',
'name': 'None',
'qname': 'builtins.None',
'name': 'bool',
'qname': '',
}),
dict({
'kind': 'NamedType',
'name': 'float',
'name': 'str',
'qname': '',
}),
dict({
'kind': 'NamedType',
'name': 'bool',
'qname': 'builtins.bool',
'name': 'InferMe',
'qname': 'tests.data.test_package.infer_types_module.InferMe',
}),
dict({
'kind': 'NamedType',
'name': 'str',
'qname': '',
'name': 'bool',
'qname': 'builtins.bool',
}),
dict({
'kind': 'NamedType',
'name': 'bool',
'qname': '',
'name': 'None',
'qname': 'builtins.None',
}),
dict({
'kind': 'NamedType',
'name': 'InferMyTypes',
'qname': 'tests.data.test_package.infer_types_module.InferMyTypes',
'name': 'int',
'qname': 'builtins.int',
}),
dict({
'kind': 'NamedType',
'name': 'int',
'qname': 'builtins.int',
'qname': '',
}),
]),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@
static attr noTypeHintPublic: Int
@PythonName("object_attr")
static attr objectAttr: AttributesClassA
// TODO Attribute has no type information.
@PythonName("callexpr_attr")
static attr callexprAttr: Any
static attr callexprAttr
// TODO Safe-DS does not support tuple types.
@PythonName("tuple_attr_1")
static attr tupleAttr1: Tuple<Any>
Expand Down

0 comments on commit 8b44fe6

Please sign in to comment.