Skip to content

Commit

Permalink
Drop support for Python 3.6 completely
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobiasd committed Dec 19, 2020
1 parent b346e58 commit 46083bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 43 deletions.
44 changes: 10 additions & 34 deletions undictify/_unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,10 @@
"""
import enum
import inspect
import sys
from dataclasses import InitVar, is_dataclass
from functools import wraps
from typing import Any, Callable, Dict, List, Optional, Type, TypeVar, Union, get_type_hints, Tuple

VER_3_7_AND_UP = sys.version_info[:3] >= (3, 7, 0) # PEP 560

# pylint: disable=no-name-in-module,ungrouped-imports,import-error
if VER_3_7_AND_UP:
from typing import _GenericAlias # type: ignore
from dataclasses import InitVar, is_dataclass
else:
from typing import _Union # type: ignore
# pylint: enable=no-name-in-module,ungrouped-imports,import-error
from typing import _GenericAlias # type: ignore

TypeT = TypeVar('TypeT')

Expand Down Expand Up @@ -92,7 +83,7 @@ def inner(first_arg: Any, *args: Any, **kwargs: Any) -> TypeT:
func.__new__ = wrapper(func.__new__, signature_new) # type: ignore
else:
func.__init__ = wrapper(func.__init__, _get_signature(func.__init__)) # type: ignore
if _is_dataclass(func) and hasattr(func, '__post_init__'):
if is_dataclass(func) and hasattr(func, '__post_init__'):
func.__post_init__ = wrapper(func.__post_init__, # type: ignore
_get_signature(func.__post_init__)) # type: ignore
setattr(func, '__undictify_wrapped_func__', func)
Expand Down Expand Up @@ -378,26 +369,20 @@ def _is_initvar_type(the_type: Callable[..., TypeT]) -> bool:
Therefore, the code below checks for both cases to support 3.7 and 3.8
"""
if VER_3_7_AND_UP:
return the_type == InitVar or isinstance(the_type, InitVar) # type: ignore
return False
return the_type == InitVar or isinstance(the_type, InitVar) # type: ignore


def _is_union_type(the_type: Callable[..., TypeT]) -> bool:
"""Return True if the type is a Union."""
if VER_3_7_AND_UP:
return (the_type is Union or # type: ignore
_is_instance(the_type, _GenericAlias) and _type_origin_is(the_type, Union))
return _is_instance(the_type, _Union)
return (the_type is Union or # type: ignore
_is_instance(the_type, _GenericAlias) and _type_origin_is(the_type, Union))


def _is_list_type(the_type: Callable[..., TypeT]) -> bool:
"""Return True if the type is a List."""
try:
if VER_3_7_AND_UP:
return _is_instance(the_type,
_GenericAlias) and _type_origin_is(the_type, list)
return issubclass(the_type, List) # type: ignore
return _is_instance(the_type,
_GenericAlias) and _type_origin_is(the_type, list)
except TypeError:
return False

Expand All @@ -415,10 +400,8 @@ def _is_optional_list_type(the_type: Callable[..., TypeT]) -> bool:
def _is_dict_type(the_type: Callable[..., TypeT]) -> bool:
"""Return True if the type is a Dict."""
try:
if VER_3_7_AND_UP:
return _is_instance(the_type,
_GenericAlias) and _type_origin_is(the_type, dict)
return issubclass(the_type, Dict) # type: ignore
return _is_instance(the_type,
_GenericAlias) and _type_origin_is(the_type, dict)
except TypeError:
return False

Expand Down Expand Up @@ -531,13 +514,6 @@ def _is_none_type(value: TypeT) -> bool:
return value is type(None)


def _is_dataclass(value: TypeT) -> bool:
"""Return True if the value is a dataclass"""
if VER_3_7_AND_UP:
return is_dataclass(value)
return False


def _is_dict(value: TypeT) -> bool:
"""Return True if the value is a dictionary."""
return isinstance(value, dict)
Expand Down
10 changes: 1 addition & 9 deletions undictify/tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""
undictify - tests
"""

import dataclasses
import enum
import json
import pickle
import sys
import unittest
from datetime import datetime
from typing import Any, Callable, Dict, List, NamedTuple, Optional, Union, Tuple
Expand All @@ -16,11 +15,6 @@

TypeT = TypeVar('TypeT')

VER_3_7_AND_UP = sys.version_info[:3] >= (3, 7, 0) # PEP 560

if VER_3_7_AND_UP:
import dataclasses # pylint: disable=import-error


# pylint: disable=too-many-lines

Expand Down Expand Up @@ -1284,8 +1278,6 @@ def test_without_optionals(self) -> None:
self.assertEqual('foo', obj.name)


@unittest.skipIf(not VER_3_7_AND_UP,
"Python version is not high enough")
class TestDataClasses(unittest.TestCase):
"""Tests that data classes work as expected"""

Expand Down

0 comments on commit 46083bd

Please sign in to comment.