Skip to content

Commit

Permalink
Merge pull request #207 from nucleic/union-typevar-bound
Browse files Browse the repository at this point in the history
Support Union as TypeVar bound
  • Loading branch information
MatthieuDartiailh authored Jan 23, 2024
2 parents 4eea89e + 58e80d7 commit a9e7fa3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12-dev']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
- name: Get history and tags for SCM versioning to work
Expand Down
72 changes: 42 additions & 30 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,7 @@ jobs:
name: artifact
path: dist/*.whl

release_upload:
name: Create Release and Upload Release Asset
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs: [build_wheels, build_sdist]
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: ${{ contains(github.ref, 'rc') || contains(github.ref, 'a') || contains(github.ref, 'b')}}
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- name: Upload Release Asset
id: upload-release-asset
uses: shogo82148/actions-upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/*

upload_pypi:
publish:
if: github.event_name == 'push'
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
Expand All @@ -122,3 +93,44 @@ jobs:
password: ${{ secrets.pypi_password }}
# To test:
# repository_url: https://test.pypi.org/legacy/

github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and create a GitHub Release
runs-on: ubuntu-latest
needs:
- publish

permissions:
contents: write
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
password: ${{ secrets.pypi_password }}
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--generate-notes
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
3 changes: 1 addition & 2 deletions atom/typing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ def _extract_types(kind: TypeLike) -> Tuple[type, ...]:
raise ValueError(
"Forward reference in type var bounds are not supported."
)
assert isinstance(b, type)
extracted.append(b)
extracted.extend(_extract_types(b))
elif t.__constraints__:
raise ValueError("Constraints in type var are not supported.")
else:
Expand Down
5 changes: 5 additions & 0 deletions releasenotes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Atom Release Notes
==================

0.10.4 - 23/01/2024
-------------------

- allow unions in TypeVar bound PR #207

0.10.3 - 04/10/2023
-------------------

Expand Down
2 changes: 2 additions & 0 deletions tests/test_typing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

T = TypeVar("T")
U = TypeVar("U", bound=int)
UU = TypeVar("UU", bound=Union[int, str])
V = TypeVar("V", int, float)
W = TypeVar("W", contravariant=True)

Expand Down Expand Up @@ -50,6 +51,7 @@ def test_extract_types(ty, outputs):
def test_extract_types_for_type_vars():
assert extract_types(T) == (object,)
assert extract_types(U) == (int,)
assert extract_types(UU) == (int, str)
with pytest.raises(ValueError) as e:
extract_types(V)
assert "Constraints" in e.exconly()
Expand Down

0 comments on commit a9e7fa3

Please sign in to comment.