Skip to content

Commit

Permalink
Test on Python 3.11 and Python 3.12 too (#21)
Browse files Browse the repository at this point in the history
* Test on Python 3.11 and Python 3.12 too

* Remove no-longer-needed ignore comments for mypy

* Fix empty unit-test error code with Python 3.12

* Add newline to end of docker-compose file
  • Loading branch information
Dobiasd authored Apr 2, 2024
1 parent 5436a9e commit 7bda86f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [ "3.7", "3.8", "3.9", "3.10" ]
python: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12" ]
name: python-${{ matrix.python }}
steps:
- name: Checkout
Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,21 @@ services:
- .:/undictify
working_dir: /undictify
entrypoint: ./test/install_from_local_and_run_code_checks.sh

unit-tests-3-11:
build:
context: .
dockerfile: test/Dockerfile_3.11
volumes:
- .:/undictify
working_dir: /undictify
entrypoint: ./test/install_from_local_and_run_code_checks.sh

unit-tests-3-12:
build:
context: .
dockerfile: test/Dockerfile_3.12
volumes:
- .:/undictify
working_dir: /undictify
entrypoint: ./test/install_from_local_and_run_code_checks.sh
4 changes: 4 additions & 0 deletions test/Dockerfile_3.11
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM python:3.11

RUN pip3 install --upgrade pip
RUN pip3 install pylint mypy
4 changes: 4 additions & 0 deletions test/Dockerfile_3.12
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM python:3.12

RUN pip3 install --upgrade pip
RUN pip3 install pylint mypy
2 changes: 1 addition & 1 deletion test/run_code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -e

find undictify -iname "*.py" | grep -v -e "__init__.py" | xargs -L 1 pylint
find undictify -iname "*.py" | grep -v -e "__init__.py" | xargs -L 1 mypy --strict
find undictify -iname "*.py" | grep -v -e "__init__.py" | xargs -L 1 python3 -m unittest
python3 -m unittest undictify/tests.py
12 changes: 5 additions & 7 deletions undictify/_unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def _get_value(func: WrappedOrFunc[TypeT],
if _is_optional_type(func) or _is_union_type(func) \
else [func]))

if func is inspect.Parameter.empty and param_name != 'self': # type: ignore
if func is inspect.Parameter.empty and param_name != 'self':
raise TypeError(f'Parameter {param_name} of target function '
'is missing a type annotation.')

Expand Down Expand Up @@ -299,7 +299,7 @@ def _get_value(func: WrappedOrFunc[TypeT],
f'into type {_get_type_name(func)} '
f'for key {param_name}.')
try:
if isinstance(value, str) and func is bool: # type: ignore
if isinstance(value, str) and func is bool:
return _string_to_bool(value)
return func(value)
except ValueError as ex:
Expand Down Expand Up @@ -375,7 +375,7 @@ def _is_initvar_type(the_type: Callable[..., TypeT]) -> bool:
Therefore, the code below checks for both cases to support 3.7 and 3.8
"""
return the_type == InitVar or isinstance(the_type, InitVar) # type: ignore
return the_type == InitVar or isinstance(the_type, InitVar)


def _is_union_type(the_type: Callable[..., TypeT]) -> bool:
Expand Down Expand Up @@ -416,7 +416,7 @@ def _is_dict_type(the_type: Callable[..., TypeT]) -> bool:

def _type_origin_is(the_type: Callable[..., TypeT], origin: Any) -> bool:
assert hasattr(the_type, '__origin__')
return the_type.__origin__ is origin # type: ignore
return the_type.__origin__ is origin


def _get_union_types(union_type: Callable[..., TypeT]) -> List[Callable[..., TypeT]]:
Expand Down Expand Up @@ -478,10 +478,8 @@ def _isinstanceofone(value: Callable[..., TypeT], types: List[Callable[..., Type
if _isinstanceofone(value, _get_union_types(the_type)):
return True
try:
# pylint: disable=unidiomatic-typecheck
if type(value) == the_type: # type: ignore
if type(value) == the_type: # pylint: disable=unidiomatic-typecheck
return True
# pylint: enable=unidiomatic-typecheck
except TypeError:
pass
return False
Expand Down

0 comments on commit 7bda86f

Please sign in to comment.