Skip to content

Commit

Permalink
Add Python 3.13, drop Python 3.8, update tool versions (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
wRAR authored Oct 16, 2024
1 parent 3194565 commit 12012b2
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: '3.13'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v4
Expand All @@ -40,7 +40,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.10']
python-version: ['3.13']
tox-job: ["mypy", "twinecheck"]

steps:
Expand Down
9 changes: 4 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Installation

pip install andi

andi requires Python >= 3.8.1.
andi requires Python >= 3.9.

Goal
====
Expand Down Expand Up @@ -402,10 +402,9 @@ Union
Annotated
---------

On Python 3.9+ ``Annotated`` type annotations can be used to attach arbitrary
metadata that will be preserved in the plan. Occurrences of the same type
annotated with different metadata will not be considered duplicates. For
example:
``Annotated`` type annotations can be used to attach arbitrary metadata that
will be preserved in the plan. Occurrences of the same type annotated with
different metadata will not be considered duplicates. For example:

.. code-block:: python
Expand Down
12 changes: 3 additions & 9 deletions andi/typeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import inspect
import types
import functools
from typing import Union, List, Callable, Dict, Container, cast, Type, get_type_hints
from typing import Annotated, Union, List, Callable, Dict, Container, cast, Type, get_args, get_origin, get_type_hints


def is_union(tp) -> bool:
Expand All @@ -23,10 +23,8 @@ def is_union(tp) -> bool:
def get_type_hints_with_extras(obj, *args, **kwargs):
"""
Like get_type_hints, but sets include_extras=True
for Python versions which support Annotated
"""
if sys.version_info >= (3, 9):
kwargs["include_extras"] = True
kwargs["include_extras"] = True
return get_type_hints(obj, *args, **kwargs)


Expand Down Expand Up @@ -156,17 +154,13 @@ def get_callable_func_obj(class_or_func: Callable) -> Callable:


def is_typing_annotated(o: Callable) -> bool:
"""Return True if the input is typing.Annotated and Python is 3.9+"""
if sys.version_info < (3, 9):
return False
from typing import Annotated, get_origin
"""Return True if the input is typing.Annotated"""
return get_origin(o) == Annotated


def strip_annotated(o: Callable) -> Callable:
"""Return the underlying type for Annotated, the input itself otherwise."""
if is_typing_annotated(o):
from typing import get_args
return get_args(o)[0]
else:
return o
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
packages=find_packages(exclude=['tests']),
package_data={"andi": ["py.typed"]},
zip_safe=False,
python_requires='>=3.8.1',
python_requires='>=3.9',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
],
)
16 changes: 0 additions & 16 deletions tests/test_dataclasses_support.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import sys
from typing import ForwardRef

import pytest

import andi
from tests.types import ADCnp, BDCnp
from tests.types_pep563 import ADC, ADCStrRef, BDC
Expand All @@ -18,16 +13,5 @@ def test_dataclasses_forward_refs():
assert andi.inspect(ADCnp.__init__) == {'b': [BDCnp]}


@pytest.mark.skipif(sys.version_info >= (3, 9, 0),
reason="Tests pre-3.9 behavior of forward refs.")
def test_dataclasses_py37_str_ref():
""" String annotations are returned as ForwardRef when
``from __future__ import annotations`` is used. Just don declare them as string. """
assert type(andi.inspect(ADCStrRef.__init__)['b'][0]) == ForwardRef


@pytest.mark.skipif(sys.version_info < (3, 9, 0),
reason="Dataclasses with string forward references in "
"Python >= 3.9 are resolved as types :-)")
def test_dataclasses_py39_str_ref():
assert andi.inspect(ADCStrRef.__init__) == {'b': [BDC]}
6 changes: 1 addition & 5 deletions tests/test_inspect.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
from functools import wraps, partial
from typing import Union, Optional, TypeVar, Type
from typing import Union, Optional, TypeVar, Type, Annotated

import pytest

Expand Down Expand Up @@ -136,10 +135,7 @@ def __call__(self, x: Bar):
assert andi.inspect(obj) == {'x': [Bar]}


@pytest.mark.skipif(sys.version_info < (3, 9), reason="No Annotated support in Python < 3.9")
def test_annotations():
from typing import Annotated

def f(x: Annotated[int, 42]) -> None:
pass

Expand Down
9 changes: 1 addition & 8 deletions tests/test_plan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
from functools import partial
from typing import Union, Optional, Dict, Callable
from typing import Union, Optional, Dict, Callable, Annotated

import pytest

Expand Down Expand Up @@ -462,10 +461,7 @@ def test_plan_overrides(recursive_overrides):
plan == [(B, {}), (A, {}), (C, {'a': A, 'b': B}), (D, {'a': A, 'c': C})])


@pytest.mark.skipif(sys.version_info < (3, 9), reason="No Annotated support in Python < 3.9")
def test_plan_annotations():
from typing import Annotated

class MyFunc:
def __call__(self, b: Annotated[B, 42]):
pass
Expand All @@ -475,10 +471,7 @@ def __call__(self, b: Annotated[B, 42]):
assert plan == [(Annotated[B, 42], {}), (func, {'b': Annotated[B, 42]})]


@pytest.mark.skipif(sys.version_info < (3, 9), reason="No Annotated support in Python < 3.9")
def test_plan_annotations_duplicate():
from typing import Annotated

class MyFunc:
def __call__(self,
b: Annotated[B, 42],
Expand Down
6 changes: 1 addition & 5 deletions tests/test_typeutils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
from typing import Union, Optional, get_type_hints
from typing import Union, Optional, get_type_hints, Annotated

import pytest

Expand Down Expand Up @@ -82,10 +81,7 @@ def meth(self):
assert get_callable_func_obj(foo) == foo.__call__


@pytest.mark.skipif(sys.version_info < (3, 9), reason="No Annotated support in Python < 3.9")
def test_get_hint_extras():
from typing import Annotated

def f(x: Annotated[int, 42]) -> None:
pass

Expand Down
14 changes: 7 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py38,py39,py310,py311,py312,mypy,twinecheck
envlist = py39,py310,py311,py312,py313,mypy,twinecheck

[testenv]
deps =
Expand All @@ -17,17 +17,17 @@ commands =

[testenv:mypy]
deps =
mypy==0.971
types-attrs
mypy==1.11.2
attrs>=18.2.0
pytest

commands = mypy --show-error-codes --ignore-missing-imports --no-warn-no-return \
andi tests
commands = mypy andi tests

[testenv:twinecheck]
basepython = python3
deps =
twine==4.0.2
build==1.0.3
twine==5.1.1
build==1.2.2
commands =
python -m build --sdist
twine check dist/*

0 comments on commit 12012b2

Please sign in to comment.