Skip to content

Commit

Permalink
Added Python 3.7 support and dropped Python 3.3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Jul 8, 2018
1 parent f311a90 commit 3a7b881
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
16 changes: 9 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@ jobs:
cache: pip
python: pypy3

- env: TOXENV=py33
python: "3.3"
- env: TOXENV=py34
python: "3.4"
after_success: &after_success
- pip install coveralls
- coveralls

- env: TOXENV=py34
python: "3.4"
after_success: *after_success

- env: TOXENV=py35
python: "3.5.0"
after_success: *after_success
Expand All @@ -37,6 +33,12 @@ jobs:
python: "3.6"
after_success: *after_success

- env: TOXENV=py37
python: "3.7"
dist: xenial
sudo: required
after_success: *after_success

- stage: deploy to pypi
install: skip
script: skip
Expand All @@ -49,7 +51,7 @@ jobs:
on:
tags: true

python: "3.3"
python: "3.4"

install: pip install tox

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Version history

This library adheres to `Semantic Versioning <http://semver.org/>`_.

**2.2.0**

- Fixed compatibility with Python 3.7
- Removed support for Python 3.3

**2.1.4** (2018-01-07)

- Removed support for backports.typing, as it has been removed from PyPI
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6'
'Programming Language :: Python :: 3.7'
],
license='MIT',
zip_safe=True,
py_modules=['typeguard'],
python_requires='>= 3.3',
python_requires='>= 3.4',
setup_requires=[
'setuptools_scm >= 1.7.0'
],
extras_require={
':python_version == "3.3"': 'typing >= 3.5',
':python_version == "3.4"': 'typing >= 3.5',
'testing': ['pytest', 'pytest-cov']
}
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
minversion = 2.5.0
envlist = pypy3, py33, py34, py35, py36, flake8
envlist = pypy3, py34, py35, py36, py37, flake8
skip_missing_interpreters = true

[testenv]
Expand Down
34 changes: 20 additions & 14 deletions typeguard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import collections
import collections.abc
import gc
import inspect
import sys
Expand Down Expand Up @@ -284,6 +284,10 @@ def check_class(argname: str, value, expected_type, memo: _CallMemo) -> None:
raise TypeError('type of {} must be a type; got {} instead'.format(
argname, qualified_name(value)))

# Needed on Python 3.7+
if expected_type is Type:
return

expected_class = expected_type.__args__[0] if expected_type.__args__ else None
if expected_class:
if isinstance(expected_class, TypeVar):
Expand Down Expand Up @@ -338,10 +342,19 @@ def check_number(argname: str, value, expected_type):

# Equality checks are applied to these
origin_type_checkers = {
Callable: check_callable,
collections.abc.Callable: check_callable,
dict: check_dict,
Dict: check_dict,
list: check_list,
List: check_list,
Sequence: check_sequence,
collections.abc.Sequence: check_sequence,
set: check_set,
Set: check_set,
tuple: check_tuple,
Tuple: check_tuple,
type: check_class,
Union: check_union
}
_subclass_check_unions = hasattr(Union, '__union_set_params__')
Expand Down Expand Up @@ -369,18 +382,14 @@ def check_type(argname: str, value, expected_type, memo: _CallMemo) -> None:
# Only happens on < 3.6
expected_type = type(None)

if isclass(expected_type):
origin_type = getattr(expected_type, '__origin__', None)
if origin_type is not None:
checker_func = origin_type_checkers.get(origin_type)
if checker_func:
checker_func(argname, value, expected_type, memo)
return

origin_type = getattr(expected_type, '__origin__', None)
if origin_type is not None:
checker_func = origin_type_checkers.get(origin_type)
if checker_func:
checker_func(argname, value, expected_type, memo)
elif isclass(expected_type):
if issubclass(expected_type, Tuple):
check_tuple(argname, value, expected_type, memo)
elif issubclass(expected_type, Callable) and hasattr(expected_type, '__args__'):
check_callable(argname, value, expected_type, memo)
elif issubclass(expected_type, (float, complex)):
check_number(argname, value, expected_type)
elif _subclass_check_unions and issubclass(expected_type, Union):
Expand All @@ -397,9 +406,6 @@ def check_type(argname: str, value, expected_type, memo: _CallMemo) -> None:
elif isinstance(expected_type, TypeVar):
# Only happens on < 3.6
check_typevar(argname, value, expected_type, memo)
elif getattr(expected_type, '__origin__', None) is Union:
# Only happens on 3.6+
check_union(argname, value, expected_type, memo)


def check_return_type(retval, memo: _CallMemo) -> bool:
Expand Down

0 comments on commit 3a7b881

Please sign in to comment.