Skip to content

feat: Infer the type for attributes from the assigned value with mypy #34

@Masara

Description

@Masara

Is your feature request related to a problem?

Attributes, parameters and results in stubs, which are generated from python code, currently have no type information if the python code did not have type hints. Example:

# Python Code
class A:
    attr1: int
    attr2 = 2

    def my_func(a = 1):
        return a
// Safe-DS stubs
class A() {
    attr1: Int
    attr2

    fun myFunc(a = 1) -> result1: Any
}    

Furthermore, currently, if a function has no return type specified, the API will generate "Any" as the return type. This value has to be removed and the type has to be either inferred with mypy or left empty.

Desired solution

The API Class has to be adjusted to also infer type information with mypy if no type hints are given.
Then the following should be done:

  1. Try to infer the type from the assigned value if mypy offers this functionality.
// Safe-DS stubs
class A() {
    attr1: Int
    attr2: Int

    fun myFunc(a: Int = 1) -> result1: Int
}    
  1. If this is not possible (in general or for a specific case) add a TODO.
// Safe-DS stubs
class A() {
    attr1: Int
    // TODO Attribute has no type information.
    attr2

    // TODO Parameter has no type information.
    // TODO Result has no type information.
    fun myFunc(a) -> result1
}    

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

✔️ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions