Skip to content

Commit

Permalink
remove support for python 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
cakemanny committed Sep 29, 2024
1 parent 9f6c58b commit c6834b1
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 100 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python package
name: Test Python Package

on: [push]

Expand All @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Removed
- Support for Python 3.7. If you still use Python 3.7, ensure you pin the
version to 0.7.0

## [0.7.0] - 2024-02-04
### Added
Expand Down
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PYTHON ?= python3.8
PYTHON ?= python3

venv: requirements.txt requirements-test.txt
$(PYTHON) -m venv venv
Expand All @@ -13,11 +13,6 @@ test: venv
lint: venv
venv/bin/flake8 fastclasses_json

.PHONY: test.docker
test.docker:
docker build . -f tests/Dockerfile.test -t fastclasses-json:tests
docker run -it --rm fastclasses-json:tests

publish:
venv/bin/pip install --upgrade twine build
venv/bin/python -m build
Expand Down
6 changes: 6 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* ensure tests are passing

* update changelog
* run `./scripts/release.sh`
* git push && git push --tags
* gh workflow run publish.yml
23 changes: 2 additions & 21 deletions fastclasses_json/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,8 @@
except Exception:
HAS_DATEUTIL = False

PY_37 = sys.version_info[:2] == (3, 7)

# We have to write the condition like this for mypy to recognise it
if sys.version_info >= (3, 8):
from typing import get_origin as typing_get_origin
from typing import get_args as typing_get_args
else:
from typing_extensions import get_origin as typing_get_origin
from typing_extensions import get_args as typing_get_args
from typing import get_origin as typing_get_origin
from typing import get_args as typing_get_args


_FROM = 1
Expand Down Expand Up @@ -341,9 +334,6 @@ def identity(expr):

def f(expr):
t0 = f'__{depth}'
if PY_37:
# Lazy solution for py37'ers
return f'{inner(expr)} if ({expr}) is not None else None'
return f'{inner(t0)} if ({t0}:=({expr})) is not None else None'

return f
Expand All @@ -370,13 +360,9 @@ def f(expr):
parts = ['(']
for i, inner in enumerate(inners):
xx = f'{t0}[{i}]'
if PY_37:
xx = f'({expr})[{i}]'
parts.append(f'{inner(xx)},')
parts.append(')')
e2 = ''.join(parts)
if PY_37:
return e2
# e1 is just for evaluating expr no more than once
# e2 is the actual result
return f'({e1},{e2})[1]'
Expand Down Expand Up @@ -464,11 +450,6 @@ def f(expr):
if HAS_DATEUTIL and issubclass_safe(datetime, t):
return f'dateutil.parser.isoparse({expr})'
else:
if PY_37:
return (f'{t.__name__}.fromisoformat('
f'({expr})[:-1]+"+00:00" if ({expr})[-1]=="Z" '
f'else ({expr})'
')')
return (f'{t.__name__}.fromisoformat('
f'{t0}[:-1]+"+00:00" if ({t0}:={expr})[-1]=="Z" '
f'else {t0}'
Expand Down
6 changes: 1 addition & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
},
license='MIT',
keywords='fast dataclasses json fastclasses',
python_requires='>=3.7',
install_requires=[
"typing_extensions;python_version=='3.7'"
],
python_requires='>=3.8',
extras_require={
'dev': [
'pytest',
Expand All @@ -34,7 +31,6 @@
},
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down
17 changes: 0 additions & 17 deletions tests/Dockerfile.test

This file was deleted.

49 changes: 0 additions & 49 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Dict
import sys
import textwrap

import pytest

from fastclasses_json.api import dataclass_json
from fastclasses_json import core

Expand Down Expand Up @@ -122,7 +119,6 @@ def from_dict(cls, o, *, infer_missing):
)


@pytest.mark.skipif(sys.version_info < (3, 8), reason="generates walrus operator")
def test_from_dict_source__tuple():
from typing import Tuple

Expand Down Expand Up @@ -152,36 +148,6 @@ def from_dict(cls, o, *, infer_missing):
)


@pytest.mark.skipif(sys.version_info >= (3, 8), reason="for python 3.7")
def test_from_dict_source__tuple():
from typing import Tuple

@dataclass
class A:
a: str

@dataclass
class B:
b: str

@dataclass_json
@dataclass
class C:
c: Tuple[A, B]

assert core._from_dict_source(C) == textwrap.dedent(
"""\
def from_dict(cls, o, *, infer_missing):
args = {}
value = o.get('c')
if value is not None:
value = (A._fastclasses_json_from_dict((value)[0]),B._fastclasses_json_from_dict((value)[1]),)
args['c'] = value
return cls(**args)
"""
)


def test_from_dict_source__enum():
from enum import Enum

Expand Down Expand Up @@ -247,7 +213,6 @@ class A:
'[A._fastclasses_json_from_dict(__0) for __0 in XXX]'


@pytest.mark.skipif(sys.version_info < (3, 8), reason="generates walrus operator")
def test_expr_builder__optional_enum():

class A(Enum):
Expand All @@ -261,20 +226,6 @@ class A(Enum):
assert builder('XXX') == 'A(__0) if (__0:=(XXX)) is not None else None'


@pytest.mark.skipif(sys.version_info >= (3, 8), reason="for python 3.7")
def test_expr_builder__optional_enum__py37():

class A(Enum):
X = 'ex'
Y = 'why'

t = Optional[A]

builder = core.expr_builder(t)

assert builder('XXX') == 'A(XXX) if (XXX) is not None else None'


def test_expr_builder__dict_enum():

class A(Enum):
Expand Down

0 comments on commit c6834b1

Please sign in to comment.