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

Check annotations as strings for Python 3.10 #400

Merged
merged 7 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ jobs:
run: |
sudo add-apt-repository ppa:deadsnakes/nightly
sudo apt update
sudo apt install python3.9 python3.9-venv python3.9-dev
python3.9 -m venv nightly-venv
sudo apt install python3.10 python3.10-venv python3.10-dev
python3.10 -m venv nightly-venv
echo "$PWD/nightly-venv/bin" >> $GITHUB_PATH
- name: Display Python version
run: python -c "import sys; print(sys.version)"
Expand Down
22 changes: 15 additions & 7 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2205,17 +2205,25 @@ def method(self, arg: type_) -> type_:
return arg
MyClass.__annotations__ = {'attribute': type_}

def check_annotations(obj, expected_type):
def check_annotations(obj, expected_type, expected_type_str):
assert obj.__annotations__["attribute"] == expected_type
assert obj.method.__annotations__["arg"] == expected_type
assert (
obj.method.__annotations__["return"] == expected_type
)
if sys.version_info >= (3, 10):
# In Python 3.10, type annotations are stored as strings.
# See PEP 563 for more details: https://www.python.org/dev/peps/pep-0563/
assert obj.method.__annotations__["arg"] == expected_type_str
assert (
obj.method.__annotations__["return"] == expected_type_str
)
else:
assert obj.method.__annotations__["arg"] == expected_type
assert (
obj.method.__annotations__["return"] == expected_type
)
ogrisel marked this conversation as resolved.
Show resolved Hide resolved
return "ok"

obj = MyClass()
assert check_annotations(obj, type_) == "ok"
assert worker.run(check_annotations, obj, type_) == "ok"
assert check_annotations(obj, type_, "type_") == "ok"
assert worker.run(check_annotations, obj, type_, "type_") == "ok"
ogrisel marked this conversation as resolved.
Show resolved Hide resolved

def test_generic_extensions_literal(self):
typing_extensions = pytest.importorskip('typing_extensions')
Expand Down