pytest-revealtype-injector 0.2.2__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/PKG-INFO +1 -1
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/pyproject.toml +2 -0
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/src/pytest_revealtype_injector/__init__.py +1 -1
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/src/pytest_revealtype_injector/adapter/pyright_.py +10 -0
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/src/pytest_revealtype_injector/main.py +3 -5
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/src/pytest_revealtype_injector/models.py +7 -6
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/.gitignore +0 -0
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/COPYING +0 -0
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/COPYING.mit +0 -0
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/README.md +0 -0
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/src/pytest_revealtype_injector/adapter/__init__.py +0 -0
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/src/pytest_revealtype_injector/adapter/mypy_.py +0 -0
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/src/pytest_revealtype_injector/hooks.py +0 -0
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/src/pytest_revealtype_injector/log.py +0 -0
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/src/pytest_revealtype_injector/plugin.py +0 -0
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/src/pytest_revealtype_injector/py.typed +0 -0
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/tests/conftest.py +0 -0
- {pytest_revealtype_injector-0.2.2 → pytest_revealtype_injector-0.2.3}/tests/test_basic.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pytest-revealtype-injector
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Pytest plugin for replacing reveal_type() calls inside test functions with static and runtime type checking result comparison, for confirming type annotation validity.
|
|
5
5
|
Project-URL: homepage, https://github.com/abelcheung/pytest-revealtype-injector
|
|
6
6
|
Author-email: Abel Cheung <abelcheung@gmail.com>
|
|
@@ -12,6 +12,7 @@ from typing import (
|
|
|
12
12
|
ForwardRef,
|
|
13
13
|
Literal,
|
|
14
14
|
TypedDict,
|
|
15
|
+
TypeVar,
|
|
15
16
|
cast,
|
|
16
17
|
)
|
|
17
18
|
|
|
@@ -34,10 +35,12 @@ class _PyrightDiagPosition(TypedDict):
|
|
|
34
35
|
line: int
|
|
35
36
|
character: int
|
|
36
37
|
|
|
38
|
+
|
|
37
39
|
class _PyrightDiagRange(TypedDict):
|
|
38
40
|
start: _PyrightDiagPosition
|
|
39
41
|
end: _PyrightDiagPosition
|
|
40
42
|
|
|
43
|
+
|
|
41
44
|
class _PyrightDiagItem(TypedDict):
|
|
42
45
|
file: str
|
|
43
46
|
severity: Literal["information", "warning", "error"]
|
|
@@ -46,6 +49,13 @@ class _PyrightDiagItem(TypedDict):
|
|
|
46
49
|
|
|
47
50
|
|
|
48
51
|
class _NameCollector(NameCollectorBase):
|
|
52
|
+
# Pre-register common used bare names from typing
|
|
53
|
+
collected = NameCollectorBase.collected | {
|
|
54
|
+
k: v
|
|
55
|
+
for k, v in NameCollectorBase.collected["typing"].__dict__.items()
|
|
56
|
+
if k[0].isupper() and not isinstance(v, TypeVar)
|
|
57
|
+
}
|
|
58
|
+
|
|
49
59
|
# Pyright inferred type results always contain bare names only,
|
|
50
60
|
# so don't need to bother with visit_Attribute()
|
|
51
61
|
def visit_Name(self, node: ast.Name) -> ast.Name:
|
|
@@ -126,17 +126,15 @@ def revealtype_injector(var: _T) -> _T:
|
|
|
126
126
|
adp.typechecker_result[pos] = VarType(var_name, tc_result.type)
|
|
127
127
|
|
|
128
128
|
ref = tc_result.type
|
|
129
|
+
walker = adp.create_collector(globalns, localns)
|
|
129
130
|
try:
|
|
130
|
-
_ = eval(ref.__forward_arg__, globalns, localns)
|
|
131
|
+
_ = eval(ref.__forward_arg__, globalns, localns | walker.collected)
|
|
131
132
|
except (TypeError, NameError):
|
|
132
133
|
ref_ast = ast.parse(ref.__forward_arg__, mode="eval")
|
|
133
|
-
walker = adp.create_collector(globalns, localns)
|
|
134
134
|
new_ast = walker.visit(ref_ast)
|
|
135
135
|
if walker.modified:
|
|
136
136
|
ref = ForwardRef(ast.unparse(new_ast))
|
|
137
|
-
|
|
138
|
-
else:
|
|
139
|
-
memo = TypeCheckMemo(globalns, localns)
|
|
137
|
+
memo = TypeCheckMemo(globalns, localns | walker.collected)
|
|
140
138
|
|
|
141
139
|
try:
|
|
142
140
|
check_type_internal(var, ref, memo)
|
|
@@ -47,6 +47,12 @@ class TypeCheckerError(Exception):
|
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
class NameCollectorBase(ast.NodeTransformer):
|
|
50
|
+
# typing_extensions guaranteed to be present,
|
|
51
|
+
# as a dependency of typeguard
|
|
52
|
+
collected: dict[str, Any] = {
|
|
53
|
+
m: importlib.import_module(m)
|
|
54
|
+
for m in ("builtins", "typing", "typing_extensions")
|
|
55
|
+
}
|
|
50
56
|
def __init__(
|
|
51
57
|
self,
|
|
52
58
|
globalns: dict[str, Any],
|
|
@@ -56,12 +62,7 @@ class NameCollectorBase(ast.NodeTransformer):
|
|
|
56
62
|
self._globalns = globalns
|
|
57
63
|
self._localns = localns
|
|
58
64
|
self.modified: bool = False
|
|
59
|
-
|
|
60
|
-
# as a dependency of typeguard
|
|
61
|
-
self.collected: dict[str, Any] = {
|
|
62
|
-
m: importlib.import_module(m)
|
|
63
|
-
for m in ("builtins", "typing", "typing_extensions")
|
|
64
|
-
}
|
|
65
|
+
self.collected = type(self).collected.copy()
|
|
65
66
|
|
|
66
67
|
def visit_Subscript(self, node: ast.Subscript) -> ast.expr:
|
|
67
68
|
node.value = cast("ast.expr", self.visit(node.value))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|