Skip to content

Adding support for ForwardRef in CLI#176

Merged
marcromeyn merged 15 commits intomainfrom
parse_forwardref
Apr 28, 2025
Merged

Adding support for ForwardRef in CLI#176
marcromeyn merged 15 commits intomainfrom
parse_forwardref

Conversation

@marcromeyn
Copy link
Contributor

@marcromeyn marcromeyn commented Mar 14, 2025

NeMo has quite a few string type-hints, where the import is happening inside a if TYPE_CHECKING clause. This PR adds support for that, to resolve the right type (if possible).

Signed-off-by: Marc Romeyn <marcromeyn@gmail.com>
Signed-off-by: Marc Romeyn <marcromeyn@gmail.com>
Signed-off-by: Marc Romeyn <marcromeyn@gmail.com>
Signed-off-by: Marc Romeyn <marcromeyn@gmail.com>
Signed-off-by: Marc Romeyn <marcromeyn@gmail.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
return getattr(module, type_name)
except (ImportError, AttributeError):
pass
except Exception:

Check notice

Code scanning / CodeQL

Empty except Note

'except' clause does nothing but pass and there is no explanatory comment.

Copilot Autofix

AI 10 months ago

To fix the issue, we should handle the exception in a way that provides useful information without disrupting the function's fallback behavior. The best approach is to log the exception using the logging module. This ensures that any issues are recorded for debugging purposes while maintaining the function's current behavior of returning the original annotation if resolution fails.

Changes to make:

  1. Replace the pass statement in the except Exception: block with a logging statement that records the exception.
  2. Use the logger object already defined in the file to log the exception at an appropriate level (e.g., logger.warning or logger.debug).

Suggested changeset 1
nemo_run/cli/cli_parser.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/nemo_run/cli/cli_parser.py b/nemo_run/cli/cli_parser.py
--- a/nemo_run/cli/cli_parser.py
+++ b/nemo_run/cli/cli_parser.py
@@ -1444,4 +1444,4 @@
                 pass
-    except Exception:
-        pass
+    except Exception as e:
+        logger.warning("Failed to resolve annotation '%s' in function '%s': %s", annotation, fn, e)
     return annotation
EOF
@@ -1444,4 +1444,4 @@
pass
except Exception:
pass
except Exception as e:
logger.warning("Failed to resolve annotation '%s' in function '%s': %s", annotation, fn, e)
return annotation
Copilot is powered by AI and may make mistakes. Always verify output.
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
marcromeyn and others added 2 commits April 22, 2025 07:42
Signed-off-by: Marc Romeijn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <marcromeyn@gmail.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
@marcromeyn marcromeyn requested review from hemildesai and removed request for hemildesai April 23, 2025 08:18
@marcromeyn marcromeyn merged commit fa89ad7 into main Apr 28, 2025
20 checks passed
@marcromeyn marcromeyn deleted the parse_forwardref branch April 28, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding support for ForwardRef in CLI

2 participants