-
Notifications
You must be signed in to change notification settings - Fork 3
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
Static type hinting not working in PyCharm or IntelliJ #125
Comments
Hey thanks for bringing this to my attention! I can reproduce your issue and I have a preliminary workaround if you are not using mypy. You can add type hinting in your virtual environment, however mypy will complain about any attributes that aren't shared between the two types. @staticmethod
def it(
spec: type[T] | None = None,
*,
spec_set: bool = True,
side_effect: Any = None,
return_value: Any = MISSING,
_wraps_mock: (
mock.Mock
| mock.MagicMock
| mock.NonCallableMock
| mock.NonCallableMagicMock
| None
) = None,
_parent_mega_mock: _MegaMockMixin | None = None,
**kwargs,
) -> T | MegaMock[T, MegaMock | T]:
... I'll need to dig into this more to. Unfortunately Python doesn't have an intersection type, so this functions by doing some hackiness to return a union that VS Code understood to be a union while mypy was interpreting it as an If you're not using mypy and would like this functioning today, you can modify the file inside the virtual environment to add the overload with the return type definition and that should provide the functionality. Here's another example with @staticmethod
def the_class(
spec: type[T], *, spec_set: bool = True, **kwargs
) -> type[T] | MegaMock[type[T], MegaMock[Any, Any] | T]:
... The status of intersection types can be tracked here: |
* Use no_type_check instead of hack * Increment version
@christianplatta1012 I pushed version beta-10 which should fix the issue. Please feel free to reopen if it's still not working for you.
|
I've wrote some very simplistic test code with the Union Type and this works for IntelliJ: `from typing import Union,TypeVar T = TypeVar('T') def test_union_types(): x autocompletes with all methods from str and ClassICareAbout. |
Thanks for letting me know that it wasn't fully fixed! I was able to reproduce the issue and I just pushed out a new version that fixes that problem. It's worth calling out that if you do something like Please LMK if you find any other issues! |
It works now, thank you for you quick response and help! |
Hi,
can you explain, why the type hinting is only working in VC Code and not in PyCharm or IntelliJ?
When I type the following code, "mock_instance" won't get any type hinting in PyCharm or IntelliJ. It works in VS Code.
Is this a configuration problem?
def test_mega_mocking():
patch = MegaPatch.it(ClassICareAbout)
mock_instance = patch.megainstance
mock_instance.hello.return_value = "some value"
Best regards,
Christian
The text was updated successfully, but these errors were encountered: