-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve composability of @classmethod and @st.composite #2578
Comments
|
Unfortunately we can't do much about this at the moment, but I've been watching PEP 612 and the preceeding discussions for several years now! Once Mypy supports the PEP, we'll be able to express the way |
|
As a workaround specifically for @st.composite
@classmethod
def f(cls, draw, ...):Update: no, unfortunately we can't do anything about the order-of-arguments issue. |
|
@MaxG87 - why not use @dataclass
class FooBarTestCase:
foo: T1
bar: T2
@given(st.builds(FooBarTestCase)) # or st.from_type(FooBarTestCase)
def test_foo_bar(foo_bar_tc):
...FWIW the type of |
|
I use the
In neither of these cases However, I totally understand your reasons not to spoil the design of So, thank you for discussing this issue. I'll stick with |
|
Makes sense! If you don't need to pass arguments (aside from the class) to your strategy, using To be clear, I do intend to support this as best as we can, but as per #2634 that's just not going to be great before Python 3.10 😕 |
I frequently use the following pattern:
Please note that the order of
@classmethodand@st.compositeas well as the corresponding function arguments must be as above, i.e. of swapped order.Unfortunately, now
mypydeduces types todraw: Typeandcls: Callable[[st.SearchStrategy[...]], ...]. If I use the arguments, I get type checking warnings. The only ways I know of to get around false positives is:# type: ignore(might suppress useful warnings later on)@staticmethod(forces me to duplicate the class name)I would be glad if there could be a better way to combine
@classmethodand@st.composite. It would help if there could be a predefined type hint fordrawI could use. For sure there might be even better ways I am not aware of.The text was updated successfully, but these errors were encountered: