asserts (and a question about polymorphism) #1786
Replies: 1 comment 1 reply
-
I don't have enough information about your class hierarchy or how these classes are used, but based on the code you posted, it seems like the _DO = TypeVar("_DO", bound=DataObject)
class Filter(Generic[_DO]):
...
def GetOutput(self)->_DO: ... This would eliminate the need for asserts or other runtime checks to verify that it's an expected subclass. You are correct that Python can be run using the An assert statement should not be used for control flow; it should be used to document an assumption that you are making in your code. If your intent is to affect the code flow, you should use an explicit So yes, it's possible for |
Beta Was this translation helpful? Give feedback.
-
For our (boost::python) wrapped C++ we have many cases like:
Which when used in scripts leads to
My questions are two fold (and I think unrelated).
-O
argument when invoking python is there an option for asking pyright to only accept:Beta Was this translation helpful? Give feedback.
All reactions