Plugin API feedback wrgt using type hints.. I had ...
# plugins
c
Plugin API feedback wrgt using type hints.. I had to apply this diff, in order to avoid issues in pants: 🧵
Copy code
@@ -2,7 +2,7 @@ from __future__ import annotations
 
 import os.path
 from dataclasses import dataclass
-from typing import Any, Iterable, Union
+from typing import Any, Iterable, Optional, Union
 
 from pants.base.build_environment import get_buildroot
 from pants.engine.addresses import Address
@@ -98,8 +98,8 @@ Example:
 
     @classmethod
     def compute_value(
-        cls, raw_value: Iterable[str | CustomBuildStage] | None, address: Address
-    ) -> tuple[str | CustomBuildStage, ...] | None:
+        cls, raw_value: Optional[Iterable[Union[str, CustomBuildStage]]], address: Address
+    ) -> Optional[tuple[Union[str, CustomBuildStage], ...]]:
         raw_or_default = super().compute_value(raw_value, address)
Copy code
16:46:11.12 [ERROR] unsupported operand type(s) for |: 'type' and 'type'
Traceback (most recent call last):
  File "/Users/aadt/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.vVzmYz/install/lib/python3.9/site-packages/pants/bin/daemon_pants_runner.py", line 132, in single_daemonized_run
    return runner.run(start_time)
  File "/Users/aadt/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.vVzmYz/install/lib/python3.9/site-packages/pants/bin/local_pants_runner.py", line 263, in run
    engine_result = self._run_inner()
  File "/Users/aadt/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.vVzmYz/install/lib/python3.9/site-packages/pants/bin/local_pants_runner.py", line 229, in _run_inner
    return self._print_help(self.options.help_request)
  File "/Users/aadt/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.vVzmYz/install/lib/python3.9/site-packages/pants/bin/local_pants_runner.py", line 204, in _print_help
    all_help_info = HelpInfoExtracter.get_all_help_info(
  File "/Users/aadt/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.vVzmYz/install/lib/python3.9/site-packages/pants/help/help_info_extracter.py", line 269, in get_all_help_info
    name_to_target_type_info = {
  File "/Users/aadt/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.vVzmYz/install/lib/python3.9/site-packages/pants/help/help_info_extracter.py", line 270, in <dictcomp>
    alias: TargetTypeHelpInfo.create(target_type, union_membership=union_membership)
  File "/Users/aadt/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.vVzmYz/install/lib/python3.9/site-packages/pants/help/help_info_extracter.py", line 205, in create
    fields=tuple(
  File "/Users/aadt/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.vVzmYz/install/lib/python3.9/site-packages/pants/help/help_info_extracter.py", line 206, in <genexpr>
    TargetFieldHelpInfo.create(field)
  File "/Users/aadt/.cache/pants/setup/bootstrap-Darwin-x86_64/pants.vVzmYz/install/lib/python3.9/site-packages/pants/help/help_info_extracter.py", line 158, in create
    raw_value_type = get_type_hints(field.compute_value)["raw_value"]
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 1469, in get_type_hints
    value = _eval_type(value, globalns, localns)
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 290, in _eval_type
    return t._evaluate(globalns, localns, recursive_guard)
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 551, in _evaluate
    eval(self.__forward_code__, globalns, localns),
  File "<string>", line 1, in <module>
TypeError: unsupported operand type(s) for |: 'type' and 'type'
I would look into it, but I’m a little bit pressed for time rn.
Dang, this should go into a gh issue, of course… will fix later…
h
Yeah. This is fundamentally not possible to fix until Pants uses python 3.9. Actually I think 3.10 iirc
c
Oh..
h
It's because we use get_type_hints() to determine the help message, which cannot understand | until using a python version with it
It's only relevant for the compute_value function. Everything else can use type hints like normal
c
pity… well, it’s workaround-able 😉
h
Part of why I want to distribute Pants as a rust binary with python embedded. It would let us use python 3.10 *or let us use PyPy for performance
🚀 1
e
Caveats: although it seems likely PyPy would generally be better I think we have no proof yet. And PyPy is only up to 3.7? They always lag by a few.
âž• 1