tpaviot / ProcessScheduler

A Python package for automatic and optimized resource scheduling
https://processscheduler.github.io/
GNU General Public License v3.0
59 stars 19 forks source link

Adding Constraint Class to base for type hints #97

Closed dreinon closed 3 years ago

dreinon commented 3 years ago

I would like to specify with type hints if I return a ProcessScheduler constraint but I do not have access to Constraint class.

tpaviot commented 3 years ago

All constraints inherit from the _Constraint base class (https://github.com/tpaviot/ProcessScheduler/blob/master/processscheduler/base.py#L90).

I'm thinking about introducing a richer class hierarchy, that would be easier for the solver to adopt specific strategies.

Another thing to know, I faced many circular references issues while trying to run mypy on ProcessScheduler. Indeed, in order to get mypy properly executed, each module must imports all types.

tpaviot commented 3 years ago

To avoid circular references in type hints, I suggest following PEP 484

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

Thus the type hint could look like this:

def my_method(self, a_constraint: 'Constraint') -> None:
dreinon commented 3 years ago

Have you read this already?

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

tpaviot commented 3 years ago

No.

dreinon commented 3 years ago

Basically, importing the following can make forward references work out:

from __future__ import annotations

Although strings are totally duable. Closing the issue :smile: