From a4bed5d8d99a5789cfb6b4efc3aa068eef5b8010 Mon Sep 17 00:00:00 2001 From: James Hutchison <122519877+JamesHutchison@users.noreply.github.com> Date: Sun, 28 Jan 2024 07:25:59 -0800 Subject: [PATCH] Fix `MegaPatch.megainstance` typing for PyCharm (#127) * Fix typo in guidance * fix megapatch.it type hinting for pycharm * Commit organizeImports setting automigration * Increment version --- .vscode/settings.json | 4 ++-- GUIDANCE.md | 4 ++-- megamock/megapatches.py | 7 ++++--- pyproject.toml | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 257dc08..f434a0f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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" diff --git a/GUIDANCE.md b/GUIDANCE.md index e3d4401..15d8c98 100644 --- a/GUIDANCE.md +++ b/GUIDANCE.md @@ -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(...) ``` diff --git a/megamock/megapatches.py b/megamock/megapatches.py index 40e8a89..904a379 100644 --- a/megamock/megapatches.py +++ b/megamock/megapatches.py @@ -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 @@ -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, @@ -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. @@ -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, diff --git a/pyproject.toml b/pyproject.toml index a80c278..605b97e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] readme = "README.md"