opencog / rocca

Rational OpenCog Controlled Agent (ROCCA). Use OpenCog to control a rational agent in OpenAI Gym and Malmo environments.
GNU Affero General Public License v3.0
32 stars 18 forks source link

Type annotate python code #26

Closed ngeiswei closed 2 years ago

ngeiswei commented 3 years ago

Out-of-the-box type annotation has been introduced in Python 3.5

https://www.python.org/dev/peps/pep-0484/

and substantially improved in Python 3.9

https://www.python.org/dev/peps/pep-0585/

Already some functions have been annotated by Adrian

https://github.com/opencog/rocca/blob/45ae155aecf1de8a4702bddd97647e48fc2fcf2a/examples/cartpole.py#L110 https://github.com/opencog/rocca/blob/45ae155aecf1de8a4702bddd97647e48fc2fcf2a/rocca/envs/wrappers/utils.py#L40

It would be very good if we take the habit to annotate all of them. We could also add, alongside the test suite #25, an easy-to-run 1-liner static checker command (using mypy or such).

Let us choose light over darkness, truth over lies, type annotation over technological apocalypse.

ntoxeg commented 3 years ago

One thing of note is that unfortunately we can’t really type check Atomese types, as the way the bindings for Python are generated results in a bunch of helper functions that do not represent types. So for example, you can’t use Python’s isinstance to check for Atomese types, you can only type check against the generic Atom type. For checking types you have to use the low-level method of comparing their number IDs manually.

Fixing this would require an overhaul of Python bindings, such that we generate actual Python types (i. e. classes) for each type.

github-actions[bot] commented 3 years ago

Detected no activity for this issue in the last 60 days. The issue will be closed in 7 days if no further activity occurs.

ntoxeg commented 3 years ago

More type annotations added by #32. There is a problem with using mypy though - all the existing OpenCog Python packages have to be modified to provide type annotations and a py.typed file has to be added to signify that they provide type information.

github-actions[bot] commented 2 years ago

Detected no activity for this issue in the last 60 days. The issue will be closed in 7 days if no further activity occurs.

ngeiswei commented 2 years ago

PR #34 adds type annotations for all functions and methods of

https://github.com/opencog/rocca/blob/master/rocca/agents/core.py https://github.com/opencog/rocca/blob/master/rocca/agents/utils.py

Many files still remain un-annotated.

ngeiswei commented 2 years ago

I'm closing that issue as the core code is fairly well type-annotated.