Skip to content

Commit

Permalink
1.9.0 Future annotation update support and dockerize version testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-makowski committed Jan 28, 2025
1 parent e017429 commit 49ad406
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 319 deletions.
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# syntax = docker/dockerfile:1
# FROM python:3.9-bookworm
# FROM python:3.10-bookworm
# FROM python:3.11-bookworm
# FROM python:3.12-bookworm
# FROM python:3.13-bookworm
FROM python:3.14-rc-bookworm

# Set python to unbuffered mode
ENV PYTHONUNBUFFERED=1

# Set the working directory to /app
WORKDIR /app/

# Copy and install the requirements
# This includes egg installing the type_enforced package
COPY type_enforced/__init__.py /app/type_enforced/__init__.py
COPY pyproject.toml /app/pyproject.toml
COPY requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt

COPY ./run_tests.sh /app/run_tests.sh
ENTRYPOINT ["/app/run_tests.sh"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Connor Makowski
Copyright (c) 2025 Connor Makowski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 0 additions & 3 deletions build/lib/type_enforced/__init__.py

This file was deleted.

281 changes: 0 additions & 281 deletions build/lib/type_enforced/enforcer.py

This file was deleted.

25 changes: 0 additions & 25 deletions build/lib/type_enforced/utils.py

This file was deleted.

5 changes: 5 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
python --version
for f in /app/test/*.py;
do python "$f";
done
6 changes: 5 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
for f in test/*.py; do python "$f"; done
docker build . --tag "type_enforced" --quiet
docker run --rm \
--volume "$(pwd):/app" \
"type_enforced"

7 changes: 0 additions & 7 deletions test_version.sh

This file was deleted.

9 changes: 8 additions & 1 deletion type_enforced/enforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __get_checkable_types__(self):
if not hasattr(self, "__checkable_types__"):
self.__checkable_types__ = {
key: self.__get_checkable_type__(value)
for key, value in self.__annotations__.items()
for key, value in self.__fn__.__annotations__.items()
}
self.__return_type__ = self.__checkable_types__.pop("return", None)

Expand Down Expand Up @@ -313,6 +313,10 @@ def Enforcer(clsFnMethod, enabled):
clsFnMethod.__enforcer_enabled__ = enabled
if clsFnMethod.__enforcer_enabled__ == False:
return clsFnMethod
# Support eager annotations for python 3.14+
if hasattr(clsFnMethod, "__annotate__"):
if not hasattr(clsFnMethod, "__annotations__") and getattr(clsFnMethod, "__annotate__") is not None:
clsFnMethod.__annotations__==clsFnMethod.__annotate__(2)
if isinstance(
clsFnMethod, (staticmethod, classmethod, FunctionType, MethodType)
):
Expand All @@ -327,6 +331,9 @@ def Enforcer(clsFnMethod, enabled):
return FunctionMethodEnforcer(clsFnMethod)
elif hasattr(clsFnMethod, "__dict__"):
for key, value in clsFnMethod.__dict__.items():
# Skip the __annotate__ method if present in __dict__
if key == "__annotate__":
continue
if hasattr(value, "__call__") or isinstance(
value, (classmethod, staticmethod)
):
Expand Down

0 comments on commit 49ad406

Please sign in to comment.