pulp
pulp copied to clipboard
static type checks with `mypy`
Describe the new feature
Is there any way to build/install package stubs for pulp?
I was running static type check analysis with mypy but these seem missing:
file.py:19: error: Skipping analyzing "pulp": module is installed, but missing library stubs or py.typed marker [import]
Additional info
Please answer these questions before submitting your feature request.
Is your feature request related to an issue? Please include the issue number.
No, I have checked other issues, nothing seems related to this right now.
Does this feature exist in another product or project? Please provide a link.
Some project already have type stubs included inside (ex: numpy), for some others there are external packages, like pandas: https://pypi.org/project/pandas-stubs/
this is something that would be nice to have, even just to make the IDE experience more friendly. We're slowly getting docstrings and type annotations. We're a long way drom having stubs. If you feel like having a PR on any of this, it will be very welcomed.
Is there any latest progress on this issue? The infomation about type hint are here: https://peps.python.org/pep-0484/ and https://docs.python.org/3/library/typing.html Before adding type hints, we need to answer some questions.
-
Embedded or External? We can use external type hint (in *.pyi file), it will add some maintenance costs to handle seperate declarations. Or we can directly add to py files, it will force subsequent contributors to handle it.
-
what's the lowest compatible python version? Type hint having gone through multiple python versions to improve. For example,
ParamSpecandConcatenateadded in python 3.10, they are use for decorator, and we can useA | Binstead oftyping.Union[A, B]. Python 3.11 added TypeVarTuple for variadic generic support. Python 3.9 added builtin collection subscripting, we can uselist[int]instead oftyping.List[int].
Note that readme described "PuLP requires Python 3.7 or newer.". The target verion is 3.7 ?
Is there any latest progress on this issue? The infomation about type hint are here: https://peps.python.org/pep-0484/ and https://docs.python.org/3/library/typing.html Before adding type hints, we need to answer some questions.
- Embedded or External? We can use external type hint (in *.pyi file), it will add some maintenance costs to handle seperate declarations. Or we can directly add to py files, it will force subsequent contributors to handle it.
- what's the lowest compatible python version? Type hint having gone through multiple python versions to improve. For example,
ParamSpecandConcatenateadded in python 3.10, they are use for decorator, and we can useA | Binstead oftyping.Union[A, B]. Python 3.11 added TypeVarTuple for variadic generic support. Python 3.9 added builtin collection subscripting, we can uselist[int]instead oftyping.List[int].Note that readme described "PuLP requires Python 3.7 or newer.". The target verion is 3.7 ?
I'd be glad to adding this type hints.
Thanks for volunteering to help. I answer your questions:
- Embedded.
- Target version is 3.7.
Thanks for volunteering to help. I answer your questions:
- Embedded.
- Target version is 3.7.
Noted that AffineExpression inheritaged from dict, it's hard to typing, can I change the impl to inheritage from MutableMapping[KT, KV] and impl method on manual with and inner dict like __inner_dict: Dict[KT, VT]
Or we can remove those code. git log shows that they are from 11 years ago.
_DICT_TYPE = dict
if sys.platform not in ["cli"]:
# iron python does not like an OrderedDict
try:
from odict import OrderedDict
_DICT_TYPE = OrderedDict
except ImportError:
pass
try:
# python 2.7 or 3.1
from collections import OrderedDict
_DICT_TYPE = OrderedDict
except ImportError:
pass
class LpAffineExpression(_DICT_TYPE):
become
class LpAffineExpression(Dict[KT, VT]):