You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The first two instances of the overloaded declaration handle the use of literal booleans. The third handles the use of boolean expressions that still would need a cast because its type cannot be statically determined.
This requires python 3.8, which is the oldest version that did not reach its end of life. If older versions need to be supported, Literal[...] can be replaced by 'Literal[...]'.
The text was updated successfully, but these errors were encountered:
An example like this is given in PEP0586. So we could add these overloads. However, clingo still supports Python 3.6 and literal types are only available from Python 3.8 onward. The overloads would have to be added conditionally. (I know that Python 3.7 is EOL but there are still supported Linux distributions shipping with it.)
I think that it is worth adding this because with the current code one has to add this annoying cast/assertion. The conditional import could be done like this:
try:
fromtypingimportLiteralHAS_LITERAL_TYPE=TrueexceptImportError:
HAS_LITERAL_TYPE=False
...
# the first two overloads are subject to this conditionifHAS_LITERAL_TYPE:
...
Putting the type in quotes is for forward references. I did not find a pep that says we can do this for backward-compatibility. In any case, we would still have to do the conditional import (or import typing and then write 'typing.Literal[True]').
The current type definition of
control.solve()
:clingo/libpyclingo/clingo/control.py
Lines 687 to 697 in ec2c706
force us to use
cast()
with each call because of theUnion
type of its return value.It should be possible to improve this by using the
@overload
decorator on the type definition ofcontrol.solve()
as follows:with this, it should be possible to call
solve.control()
without cast whenyield_
is used with a literal as inThe first two instances of the overloaded declaration handle the use of literal booleans. The third handles the use of boolean expressions that still would need a cast because its type cannot be statically determined.
This requires python 3.8, which is the oldest version that did not reach its end of life. If older versions need to be supported,
Literal[...]
can be replaced by'Literal[...]'
.The text was updated successfully, but these errors were encountered: