Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test typing in pipelines #109

Merged
merged 15 commits into from
Oct 13, 2024
12 changes: 7 additions & 5 deletions .github/workflows/build_primary_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ jobs:
env:
CIBW_ARCHS: ${{ matrix.cibw_archs }}
CIBW_SKIP: "cp311-* cp312-* pp*"
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_REQUIRES: pytest typing_extensions mypy
CIBW_TEST_COMMAND: >
python -X faulthandler {package}/test/debug.py &&
python -X faulthandler -m pytest -p no:faulthandler -s {package}
python -X faulthandler -m pytest -p no:faulthandler -s {package} &&
python {package}/test/run_type_checker.py

- uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -61,7 +62,7 @@ jobs:
python-version: "${{ matrix.version }}"

- name: Install dependencies
run: pip install -U pip setuptools wheel pytest pytest-cov
run: pip install -U pip setuptools wheel pytest pytest-cov typing_extensions mypy

- name: Build module
run: FROZENDICT_PURE_PY=1 python setup.py bdist_wheel
Expand All @@ -72,8 +73,9 @@ jobs:
- name: Install module
run: pip install dist/*

- name: Test with pytest
run: pytest --cov=frozendict --cov-report=term-missing --cov-branch --cov-fail-under=100
- name: Run tests
run: pytest --cov=frozendict --cov-report=term-missing --cov-branch --cov-fail-under=100 &&
python test/run_type_checker.py

- uses: actions/upload-artifact@v3
with:
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/build_secondary_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ jobs:
env:
CIBW_ARCHS: ${{ matrix.cibw_archs }}
CIBW_SKIP: "cp311-* cp312-* pp*"
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_REQUIRES: pytest typing_extensions mypy
CIBW_TEST_COMMAND: >
python -X faulthandler {package}/test/debug.py &&
python -X faulthandler -m pytest -p no:faulthandler -s {package}
python -X faulthandler -m pytest -p no:faulthandler -s {package} &&
python {package}/test/run_type_checker.py

- uses: actions/upload-artifact@v3
with:
Expand All @@ -67,10 +68,11 @@ jobs:
CIBW_ARCHS: native
CIBW_BUILD: "cp310-*"
CIBW_SKIP: "*-musllinux_*"
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_REQUIRES: pytest typing_extensions mypy
CIBW_TEST_COMMAND: >
python -X faulthandler {package}/test/debug.py &&
python -X faulthandler -m pytest -p no:faulthandler -s {package}
python -X faulthandler -m pytest -p no:faulthandler -s {package} &&
python {package}/test/run_type_checker.py
with:
package-dir: dist/frozendict.tar.gz

Expand Down
17 changes: 12 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python3

import setuptools
from pathlib import Path
import sys
from platform import python_implementation
from os import environ
from pathlib import Path
from platform import python_implementation

import setuptools

name = "frozendict"
module1_name = "frozendict"
Expand All @@ -30,7 +31,10 @@
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
(
"License :: OSI Approved :: GNU Lesser General Public " +
"License v3 (LGPLv3)"
),
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Natural Language :: English",
Expand Down Expand Up @@ -97,7 +101,10 @@

include_path = c_src_path / include_dir_name
cpython_stringlib_path = cpython_object_path / cpython_stringlib_name
cpython_objects_clinic_path = cpython_object_path / cpython_objects_clinic_name

cpython_objects_clinic_path = (
cpython_object_path / cpython_objects_clinic_name
)

cpython_include_dirs = [
str(include_path),
Expand Down
4 changes: 2 additions & 2 deletions src/frozendict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from ._frozendict_py import *
c_ext = False

from .version import version as __version__
from . import cool
from . import monkeypatch
from .cool import *
from . import cool
from .version import version as __version__


def _getFrozendictJsonEncoder(BaseJsonEncoder = None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3769,6 +3769,11 @@ dictiter_iternextitem(dictiterobject *di)
Py_INCREF(result);
Py_DECREF(oldkey);
Py_DECREF(oldvalue);
// bpo-42536: The GC may have untracked this result tuple. Since we're
// recycling it, make sure it's tracked again:
if (!_PyObject_GC_IS_TRACKED(result)) {
_PyObject_GC_TRACK(result);
}
}
else {
result = PyTuple_New(2);
Expand Down
5 changes: 3 additions & 2 deletions src/frozendict/cool.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from collections.abc import MutableMapping, MutableSequence, MutableSet
from enum import Enum
from types import MappingProxyType

from array import array
from frozendict import frozendict
from collections.abc import MutableMapping, MutableSequence, MutableSet
from enum import Enum

# fix for python 3.9-

Expand Down
19 changes: 10 additions & 9 deletions src/frozendict/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ def patchOrUnpatchMutableMappingSubclasshook(
"(maybe you already unpatched MutableMapping?)"
)

oldMutableMappingSubclasshook = MutableMapping.__subclasshook__
oldMutableMappingHook = MutableMapping.__subclasshook__
else:
oldMutableMappingSubclasshook = self._oldMutableMappingSubclasshook
oldMutableMappingHook = self._oldMutableMappingSubclasshook

if patch:
# noinspection PyDecorator
Expand All @@ -157,22 +157,23 @@ def frozendictMutableMappingSubclasshook(
if issubclass(subclass, frozendict):
return False

return oldMutableMappingSubclasshook(
# noinspection PyArgumentList
return oldMutableMappingHook(
subclass,
*args,
**kwargs
)

return NotImplemented

defaultMutableMappingSubclasshook = frozendictMutableMappingSubclasshook
newOldMutableMappingSubclasshook = oldMutableMappingSubclasshook
defaultMutableMappingHook = frozendictMutableMappingSubclasshook
newOldMutableMappingHook = oldMutableMappingHook
else:
defaultMutableMappingSubclasshook = oldMutableMappingSubclasshook
newOldMutableMappingSubclasshook = None
defaultMutableMappingHook = oldMutableMappingHook
newOldMutableMappingHook = None

self._oldMutableMappingSubclasshook = newOldMutableMappingSubclasshook
MutableMapping.__subclasshook__ = defaultMutableMappingSubclasshook
self._oldMutableMappingSubclasshook = newOldMutableMappingHook
MutableMapping.__subclasshook__ = defaultMutableMappingHook

try:
# noinspection PyUnresolvedReferences, PyProtectedMember
Expand Down
Loading
Loading