Skip to content

Commit

Permalink
Fix MegaPatch.megainstance typing for PyCharm (#127)
Browse files Browse the repository at this point in the history
* Fix typo in guidance

* fix megapatch.it type hinting for pycharm

* Commit organizeImports setting automigration

* Increment version
  • Loading branch information
JamesHutchison authored Jan 28, 2024
1 parent a2e4c61 commit a4bed5d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"python.analysis.autoImportCompletions": true,
"python.analysis.indexing": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.organizeImports": "explicit"
},
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.organizeImports.ruff": true
"source.organizeImports.ruff": "explicit"
}
},
"python.analysis.typeCheckingMode": "basic"
Expand Down
4 changes: 2 additions & 2 deletions GUIDANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ There is no simple way to do this in the built-in mock library.
With MegaMock, you can do this:

```python
MegaPatch.it(MyClass)
use_real_logic(MyClass.megainstance.some_func)
patch = MegaPatch.it(MyClass)
use_real_logic(patch.megainstance.some_func)

do_test_logic(...)
```
Expand Down
7 changes: 4 additions & 3 deletions megamock/megapatches.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
from functools import cached_property
from types import ModuleType
from typing import Any, Callable, Generic, Iterable, TypeVar, cast
from typing import Any, Callable, Generic, Iterable, TypeVar, cast, no_type_check
from unittest import mock

from varname import argname # type: ignore
Expand Down Expand Up @@ -270,6 +270,7 @@ def _get_new_and_return_value_with_autospec(
new = MegaMock(return_value=return_value)
return new, return_value

@no_type_check
@staticmethod
def it(
thing: T,
Expand All @@ -282,7 +283,7 @@ def it(
new_callable: Callable | None = None,
side_effect: Any | None = None,
**kwargs: Any,
):
) -> MegaPatch[T, MegaMock[T, MegaMock | T] | T]:
"""
MegaPatch something.
Expand Down Expand Up @@ -363,7 +364,7 @@ def it(
mocker, module_path, name_to_patch, corrected_passed_in_name, new, kwargs
)

mega_patch = MegaPatch[T, type[MegaMock | T]](
mega_patch = MegaPatch(
thing=thing,
patches=patches,
new_value=new,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "megamock"
version = "0.1.0-beta.10"
version = "0.1.0-beta.11"
description = "Mega mocking capabilities - stop using dot-notated paths!"
authors = ["James Hutchison <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit a4bed5d

Please sign in to comment.