pytest-revealtype-injector 0.6.1__py3-none-any.whl → 0.6.2__py3-none-any.whl

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.
@@ -1,3 +1,3 @@
1
1
  """Pytest plugin for replacing reveal_type() calls inside test functions with static and runtime type checking result comparison, for confirming type annotation validity.""" # noqa: E501
2
2
 
3
- __version__ = "0.6.1"
3
+ __version__ = "0.6.2"
@@ -136,6 +136,25 @@ class NameCollector(NameCollectorBase):
136
136
  return node
137
137
 
138
138
 
139
+ # Mypy can insert extra character into expression so that it
140
+ # becomes invalid and unparsable. 0.9x days there
141
+ # was '*', and now '?' (and '=' for typeddict too).
142
+ # Instead of globally throwing them away (and causing
143
+ # literal string constants to not match), we iteratively
144
+ # remove chars one by one only where parsing error occurs.
145
+ #
146
+ def _strip_unwanted_char(input: str) -> str:
147
+ result = input
148
+ while True:
149
+ try:
150
+ _ = ast.parse(result)
151
+ except SyntaxError as e:
152
+ assert e.offset is not None
153
+ result = result[:e.offset-1] + result[e.offset:]
154
+ else:
155
+ return result
156
+
157
+
139
158
  class MypyAdapter(TypeCheckerAdapter):
140
159
  id = "mypy"
141
160
  _executable = "" # unused, calls mypy.api.run() here
@@ -212,12 +231,7 @@ class MypyAdapter(TypeCheckerAdapter):
212
231
  )
213
232
  if (m := self._type_mesg_re.fullmatch(diag["message"])) is None:
214
233
  continue
215
- # Mypy can insert extra character into expression so that it
216
- # becomes invalid and unparsable. 0.9x days there
217
- # was '*', and now '?' (and '=' for typeddict too).
218
- # Try stripping those character and pray we get something
219
- # usable for evaluation
220
- expression = m["type"].translate({ord(c): None for c in "*?="})
234
+ expression = _strip_unwanted_char(m["type"])
221
235
  try:
222
236
  # Unlike pyright, mypy output doesn't contain variable name
223
237
  self.typechecker_result[pos] = VarType(None, ForwardRef(expression))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-revealtype-injector
3
- Version: 0.6.1
3
+ Version: 0.6.2
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>
@@ -1,4 +1,4 @@
1
- pytest_revealtype_injector/__init__.py,sha256=wu2hLHVkWsPCsABHczD0U9APBuw8UCBvOxv6V1x5Xyg,211
1
+ pytest_revealtype_injector/__init__.py,sha256=aiBTdl1GqqEAFu1nrAFIExIe_G2uGgrFYltHSNLKUXo,211
2
2
  pytest_revealtype_injector/hooks.py,sha256=_yJD6htagRJGElrSucFbDxSHT_osdoD9Lx3P4N5sjhM,4465
3
3
  pytest_revealtype_injector/log.py,sha256=Ptd3yp1H1GlUum6BAwHc9cdyeGmaY8XYf0jp6qJmG4M,418
4
4
  pytest_revealtype_injector/main.py,sha256=3w-_CoZHTrBSC-5iX0cYMsW5rzdmmsqIwcw39x4E0EQ,5656
@@ -7,11 +7,11 @@ pytest_revealtype_injector/plugin.py,sha256=fkI6yF0dFVba0jEikIrsRp1NUQd2ohWLq4x2
7
7
  pytest_revealtype_injector/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  pytest_revealtype_injector/adapter/__init__.py,sha256=FRVB1eUrXaMzdQG0wRdIEKhx2dzGdyJcHDBb3eTTeOY,602
9
9
  pytest_revealtype_injector/adapter/basedpyright_.py,sha256=8LX7GmJmg4OZ3LKO5WoQ7Ocub6Lxi3HTStIorMApzUA,466
10
- pytest_revealtype_injector/adapter/mypy_.py,sha256=d69nGsdhkuKMPjqWMLj-KyY8HI9k6R7VaVUSw3P-IZg,9000
10
+ pytest_revealtype_injector/adapter/mypy_.py,sha256=A8Uw21qm-BRMED1HiQ13McMn8jQCVTTZDnNM2inzkBE,9314
11
11
  pytest_revealtype_injector/adapter/pyright_.py,sha256=j9121YxGeulZpRRJAO0dLFpaoTjE6t343-qS-O952QU,5122
12
- pytest_revealtype_injector-0.6.1.dist-info/METADATA,sha256=-hYQiHx1mbDeL-su0LQYwJv2L3zTEELwWs9da_cKVWA,6729
13
- pytest_revealtype_injector-0.6.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- pytest_revealtype_injector-0.6.1.dist-info/entry_points.txt,sha256=UfOm7y3WQnOoGV1mgTMb42MI6iBRPIl88FJiAOnt6SY,74
15
- pytest_revealtype_injector-0.6.1.dist-info/licenses/COPYING,sha256=LSYUX8PcSMvHCkhM5oi07eOrSLV89qdEJ-FVZmbcpNE,355
16
- pytest_revealtype_injector-0.6.1.dist-info/licenses/COPYING.mit,sha256=IzYEFDIOECyuupg_B3O9FvgjnU9i4JtambpbleoYHdQ,1060
17
- pytest_revealtype_injector-0.6.1.dist-info/RECORD,,
12
+ pytest_revealtype_injector-0.6.2.dist-info/METADATA,sha256=CgwPmLecZ0bP_Zji97wP8lxccjtPPU3o6Y_xsoBORg0,6729
13
+ pytest_revealtype_injector-0.6.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ pytest_revealtype_injector-0.6.2.dist-info/entry_points.txt,sha256=UfOm7y3WQnOoGV1mgTMb42MI6iBRPIl88FJiAOnt6SY,74
15
+ pytest_revealtype_injector-0.6.2.dist-info/licenses/COPYING,sha256=LSYUX8PcSMvHCkhM5oi07eOrSLV89qdEJ-FVZmbcpNE,355
16
+ pytest_revealtype_injector-0.6.2.dist-info/licenses/COPYING.mit,sha256=IzYEFDIOECyuupg_B3O9FvgjnU9i4JtambpbleoYHdQ,1060
17
+ pytest_revealtype_injector-0.6.2.dist-info/RECORD,,