TypeError: unsupported operand type(s) for |: Python 3.9 incompatibility in type annotations

Open Beginner friendly
#3 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
backend

Research direction

Open src/bedrock_flow_manager.py and inspect the annotations at lines 731 and 845, then check how typing imports are organized. Run the documented Python 3.9 command with the sample input; done means the module imports and the command no longer raises this TypeError.

Written by the indexing model from the issue text.

Description

Description

Running bedrock_flow_manager.py on Python < 3.10 raises a TypeError at import time due to use of the X | Y union type syntax introduced in Python 3.10.

Error

Traceback (most recent call last):
File "src/bedrock_flow_manager.py", line 71, in
class BedrockFlowManager:
File "src/bedrock_flow_manager.py", line 731, in BedrockFlowManager
def test_flow(self, flow_id: str, alias_id: str, input_text: str | list, ...
TypeError: unsupported operand type(s) for |: 'type' and 'type'

Reproducible Steps

  1. Use Python 3.9 (e.g. default on Amazon Linux 2, macOS system Python)
  2. Run python src/bedrock_flow_manager.py --test-input "What is Amazon Bedrock?"

Environment

  • Python version: 3.9.x
  • Affected file: src/bedrock_flow_manager.py (lines 731, 845)

Fix

Replace str | list and str | dict with Union[str, list] and Union[str, dict] from typing.

Dominant language
Python
Stars
100
Forks
30
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.