Skip to content

Support downgrading newer annotations #3

Description

@s0undt3ch

Consider the following diff:

--- a/src/pytestshellutils/exceptions.py
+++ b/src/pytestshellutils/exceptions.py
@@ -3,6 +3,8 @@
 """
 Pytest Shell Utilities related exceptions.
 """
+from __future__ import annotations
+
 from typing import Optional
 
 from pytestshellutils.utils.processes import ProcessResult
@@ -30,7 +32,7 @@ class ProcessFailed(ShellUtilsException):
         The ``ProcessResult`` instance when the exception occurred
     """
 
-    def __init__(self, message: str, process_result: Optional[ProcessResult] = None) -> None:
+    def __init__(self, message: str, process_result: ProcessResult | None = None) -> None:
         super().__init__()
         self.message = message
         self.process_result = process_result

lib3to6 will fail to downgrade the code and throws the following traceback

Traceback (most recent call last):                                                                        
  File "/home/vampas/.cache/pre-commit/repolg5j4qb6/py_env-python3.8/bin/downgrade-source", line 8, in <module>
    sys.exit(main())                                                                                      
  File "/home/vampas/.cache/pre-commit/repolg5j4qb6/py_env-python3.8/lib/python3.8/site-packages/downgradesource/__main__.py", line 165, in main
    exitcode = untype_source(                                                                             
  File "/home/vampas/.cache/pre-commit/repolg5j4qb6/py_env-python3.8/lib/python3.8/site-packages/downgradesource/__main__.py", line 57, in untype_source
    fixed_source_text = transpile.transpile_module(ctx, source_text)                                      
  File "/home/vampas/.cache/pre-commit/repolg5j4qb6/py_env-python3.8/lib/python3.8/site-packages/lib3to6/transpile.py", line 290, in transpile_module
    maybe_fixed_module = fixer(ctx, module_tree)                                                          
  File "/home/vampas/.cache/pre-commit/repolg5j4qb6/py_env-python3.8/lib/python3.8/site-packages/lib3to6/fixers.py", line 199, in __call__
    _FRAFContext(local_classes).remove_forward_references(tree)                                           
  File "/home/vampas/.cache/pre-commit/repolg5j4qb6/py_env-python3.8/lib/python3.8/site-packages/lib3to6/fixers.py", line 186, in remove_forward_references
    self.remove_forward_references(sub_node)                                                              
  File "/home/vampas/.cache/pre-commit/repolg5j4qb6/py_env-python3.8/lib/python3.8/site-packages/lib3to6/fixers.py", line 184, in remove_forward_references
    self.update_annotation_refs(sub_node, 'annotation')                                                   
  File "/home/vampas/.cache/pre-commit/repolg5j4qb6/py_env-python3.8/lib/python3.8/site-packages/lib3to6/fixers.py", line 167, in update_annotation_refs
    raise NotImplementedError(msg)                                                                                                                                                                                  
NotImplementedError: Error fixing annotation of forward ref with type <class '_ast.BinOp'>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions