Skip to content

Commit

Permalink
Merge pull request #212 from coveooss/feature/flex/unions-in-python-3-10
Browse files Browse the repository at this point in the history
Support 3.10 unions with |
  • Loading branch information
jonapich authored Aug 9, 2024
2 parents 6fdb473 + ce28aba commit e5dc452
Show file tree
Hide file tree
Showing 17 changed files with 1,590 additions and 1,517 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coveo-arnparse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
os: [ubuntu-latest, windows-latest, macos-11]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Run stew ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coveo-example-library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
os: [ubuntu-latest, windows-latest, macos-11]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Run stew ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coveo-functools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
os: [ubuntu-latest, windows-latest, macos-11]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Run stew ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coveo-itertools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
os: [ubuntu-latest, windows-latest, macos-11]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Run stew ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coveo-pypi-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
os: [ubuntu-latest, windows-latest, macos-11]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Run stew ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coveo-ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
os: [ubuntu-latest, windows-latest, macos-11]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Run stew ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coveo-settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
os: [ubuntu-latest, windows-latest, macos-11]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Run stew ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coveo-styles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
os: [ubuntu-latest, windows-latest, macos-11]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Run stew ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coveo-systools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
os: [ubuntu-latest, windows-latest, macos-11]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Run stew ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coveo-testing-extras.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
os: [ubuntu-latest, windows-latest, macos-11]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Run stew ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coveo-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
os: [ubuntu-latest, windows-latest, macos-11]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Run stew ci
Expand Down
11 changes: 10 additions & 1 deletion coveo-functools/coveo_functools/flex/deserializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import enum
import inspect
import logging
import sys
import warnings
from collections import abc
from contextlib import contextmanager
Expand Down Expand Up @@ -34,6 +35,11 @@
from coveo_functools.flex.subclass_adapter import get_subclass_adapter
from coveo_functools.flex.types import TypeHint, is_passthrough_type, PASSTHROUGH_TYPES

if sys.version_info >= (3, 10): # pragma: no cover
from types import UnionType
else:
from typing import Union as UnionType # :shrug:


T = TypeVar("T")

Expand Down Expand Up @@ -180,7 +186,10 @@ def deserialize(
# always puts the real type first. This is only applicable to the thing-or-list-of-things feature.
target_type: TypeHint = args[0] if args else Any

if origin is Union:
if origin in (
Union, # Union[str, int]
UnionType, # str | int (py3.10)
):
if not {*args}.difference(PASSTHROUGH_TYPES):
# Unions of PASSTHROUGH_TYPES are allowed and assumed to be in the proper type already
return cast(T, value)
Expand Down
Loading

0 comments on commit e5dc452

Please sign in to comment.