Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Python 3.9 does not support | for types. #28

Merged
merged 3 commits into from
Jan 13, 2025
Merged

Conversation

JosephCatrambone
Copy link
Contributor

On Python 3.9 the '|' isn't supported for type unions.

python -m pdb -m guardrails hub install hub://guardrails/toxic_language
Traceback (most recent call last):
  File "/Users/josephcatrambone/.pyenv/versions/3.9.19/lib/python3.9/pdb.py", line 1703, in main
    runpy._get_module_details(mainpyfile)
  File "/Users/josephcatrambone/.pyenv/versions/3.9.19/lib/python3.9/runpy.py", line 147, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/Users/josephcatrambone/.pyenv/versions/3.9.19/lib/python3.9/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/Users/josephcatrambone/.virtualenvs/test_guardrails_cli/lib/python3.9/site-packages/guardrails/__init__.py", line 12, in <module>
    from guardrails.hub.install import install
  File "/Users/josephcatrambone/.virtualenvs/test_guardrails_cli/lib/python3.9/site-packages/guardrails/hub/__init__.py", line 9, in <module>
    from guardrails_grhub_toxic_language import ToxicLanguage
  File "/Users/josephcatrambone/.virtualenvs/test_guardrails_cli/lib/python3.9/site-packages/guardrails_grhub_toxic_language/__init__.py", line 1, in <module>
    from .main import ToxicLanguage
  File "/Users/josephcatrambone/.virtualenvs/test_guardrails_cli/lib/python3.9/site-packages/guardrails_grhub_toxic_language/main.py", line 21, in <module>
    class ToxicLanguage(Validator):
  File "/Users/josephcatrambone/.virtualenvs/test_guardrails_cli/lib/python3.9/site-packages/guardrails_grhub_toxic_language/main.py", line 164, in ToxicLanguage
    def _inference_local(self, model_input: str | list) -> Any:
TypeError: unsupported operand type(s) for |: 'type' and 'type'

This does a quick replace of the '|' with an explicit union and adds the 'push to GR hub on tag'.

@JosephCatrambone JosephCatrambone merged commit 4b4abfc into main Jan 13, 2025
1 check failed
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.

2 participants