Skip to content

Clarify Python Version Compatibility #490

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

Closed
kimmeoungjun opened this issue Apr 13, 2025 · 1 comment
Closed

Clarify Python Version Compatibility #490

kimmeoungjun opened this issue Apr 13, 2025 · 1 comment
Labels
question Question about using the SDK

Comments

@kimmeoungjun
Copy link

Please read this first

  • Have you read the docs?Agents SDK docs Yes
  • Have you searched for related issues? Others may have had similar requests Yes

Question

Hi, I was trying to run the following command:

python -m examples.customer_service.main

I'm using Python 3.9.13, and when I run the script this way, I get the following error:

Traceback (most recent call last):
  File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 466, in _eval_type_backport
    return _eval_type(value, globalns, localns, type_params)
  File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 500, in _eval_type
    return typing._eval_type(  # type: ignore
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 292, in _eval_type
    return t._evaluate(globalns, localns, recursive_guard)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 554, in _evaluate
    eval(self.__forward_code__, globalns, localns),
  File "<string>", line 1, in <module>
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/kimmeoungjun/openai-agents-python/examples/customer_service/main.py", line 28, in <module>
    class AirlineAgentContext(BaseModel):
  File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_model_construction.py", line 221, in __new__
    set_model_fields(cls, config_wrapper=config_wrapper, ns_resolver=ns_resolver)
  File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_model_construction.py", line 544, in set_model_fields
    fields, class_vars = collect_model_fields(cls, config_wrapper, ns_resolver, typevars_map=typevars_map)
  File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_fields.py", line 118, in collect_model_fields
    type_hints = _typing_extra.get_model_type_hints(cls, ns_resolver=ns_resolver)
  File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 329, in get_model_type_hints
    hints[name] = try_eval_type(value, globalns, localns)
  File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 378, in try_eval_type
    return eval_type_backport(value, globalns, localns), True
  File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 429, in eval_type_backport
    return _eval_type_backport(value, globalns, localns, type_params)
  File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 474, in _eval_type_backport
    raise TypeError(
TypeError: Unable to evaluate type annotation 'str | None'. If you are making use of the new typing syntax (unions using `|` since Python 3.10 or builtins subscripting since Python 3.9), you should either replace the use of new syntax with the existing `typing` constructs or install the `eval_type_backport` package.

It seems like the code is using the | operator for union types (e.g., str | None), which is only supported in Python 3.10 and above. Since I'm running 3.9, this results in a TypeError.

From what I can tell, switching to Optional[str] (or Union[str, None]) instead of using the | operator would resolve the issue and make it compatible with Python 3.9.

I was wondering—would it make sense to either:

  • update the code to support 3.9, or
  • clarify somewhere (like in the README or pyproject.toml) that Python 3.10+ is required?

Either approach would work, but having a clear guideline on the expected Python version might help others avoid this kind of confusion. Thanks!

@kimmeoungjun kimmeoungjun added the question Question about using the SDK label Apr 13, 2025
@rm-openai
Copy link
Collaborator

Hey thanks for the report. This one is easy to fix, PR welcome. In general, the SDK supports 3.9 but the examples might not necessarily do so.

rm-openai pushed a commit that referenced this issue Apr 14, 2025
I fixed the type annotations errors for pydantic objects in some
examples as noted in #490 .

When running `make lint` the following error occurs "UP007 Use `X | Y`
for type annotations". If you know how to ignore it I will be happy to
edit the pull request, thanks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about using the SDK
Projects
None yet
Development

No branches or pull requests

2 participants