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
I noticed that I can't import, for example NonNegativeReals or Binary, without the type checker giving me the squiggly red line of badness. I dug into it and found that these are dynamically loaded into globals and they're never actually declared.
type checkers can't deal with dynamically assigned objects.
Description
I'm not sure if it's necessary to make each of them its own class or if it'd be enough to just have them declared as constants in set_types.py. Something like
frompyomo.core.base.rangeimportNumericRangefrompyomo.core.base.setimportRangeSetfromtypingimportcastNonNegativeReals=cast(RangeSet,RangeSet(
name='NonNegativeReals',
doc='A global Pyomo Set admitting any real value in [0, +inf]',
ranges=(NumericRange(0, None, 0),),
)
)
without that explicit cast it wants to be RangeSet | AbstractFiniteScalarRangeSet | AbstractInfiniteScalarRangeSet
Ideally RangeSet would have overloads so that it only returns one thing but maybe that can be the next typing improvement.
Additional information
The above could even be wrapped in an if typing block since I don't really understand the implications of the docstring to DeclareGlobalSet
The text was updated successfully, but these errors were encountered:
Summary
I noticed that I can't import, for example NonNegativeReals or Binary, without the type checker giving me the squiggly red line of badness. I dug into it and found that these are dynamically loaded into globals and they're never actually declared.
pyomo/pyomo/core/base/set.py
Lines 4548 to 4555 in cd778c5
Rationale
type checkers can't deal with dynamically assigned objects.
Description
I'm not sure if it's necessary to make each of them its own class or if it'd be enough to just have them declared as constants in set_types.py. Something like
without that explicit cast it wants to be
RangeSet | AbstractFiniteScalarRangeSet | AbstractInfiniteScalarRangeSet
Ideally
RangeSet
would have overloads so that it only returns one thing but maybe that can be the next typing improvement.Additional information
The above could even be wrapped in an
if typing
block since I don't really understand the implications of the docstring to DeclareGlobalSetThe text was updated successfully, but these errors were encountered: