Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Test
strategy:
matrix:
python-version: ["3.13", "3.12", "3.11", "3.10", "3.9"]
python-version: ["3.14", "3.13", "3.12", "3.11", "3.10", "3.9"]
runs-on: ubuntu-latest
environment: pypi-test
steps:
Expand All @@ -36,7 +36,7 @@ jobs:
coverage xml

- uses: coverallsapp/github-action@v2
if: ${{ contains(matrix.python-version, '3.13') }}
if: ${{ contains(matrix.python-version, '3.14') }}

build:
name: Build
Expand Down
55 changes: 41 additions & 14 deletions enfig/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Iterator
from os import getenv
from sys import version_info
from typing import Any, get_args

from enfig.bool_type import _Bool
Expand Down Expand Up @@ -48,24 +49,50 @@ def value(self) -> Any:
return None


class _ConfigMeta(type):
def __new__(mcs, name: str, bases: tuple, namespace: dict):
for key, type_ in namespace.get("__annotations__", {}).items():
namespace[key] = _Variable(type_, namespace.get(key, ...))
if version_info.minor < 14:

for base in bases:
if not isinstance(base, _ConfigMeta):
continue
class _ConfigMeta(type):
def __new__(mcs, name: str, bases: tuple, namespace: dict):
for key, type_ in namespace.get("__annotations__", {}).items():
namespace[key] = _Variable(type_, namespace.get(key, ...))

for variable in base:
namespace[variable.name] = variable
for base in bases:
if not isinstance(base, _ConfigMeta):
continue

return super().__new__(mcs, name, bases, namespace)
for variable in base:
namespace[variable.name] = variable

def __iter__(cls) -> Iterator[_Variable]:
return (
value for value in cls.__dict__.values() if isinstance(value, _Variable)
)
return super().__new__(mcs, name, bases, namespace)

def __iter__(cls) -> Iterator[_Variable]:
return (
value for value in cls.__dict__.values() if isinstance(value, _Variable)
)

else:
from annotationlib import Format, get_annotate_from_class_namespace # type: ignore

class _ConfigMeta(type): # type: ignore
def __new__(mcs, name: str, bases: tuple, namespace: dict):
get_annotations = get_annotate_from_class_namespace(namespace)
annotations = get_annotations(Format.VALUE) if get_annotations else {}
for key, type_ in annotations.items():
namespace[key] = _Variable(type_, namespace.get(key, ...))

for base in bases:
if not isinstance(base, _ConfigMeta):
continue

for variable in base:
namespace[variable.name] = variable

return super().__new__(mcs, name, bases, namespace)

def __iter__(cls) -> Iterator[_Variable]:
return (
value for value in cls.__dict__.values() if isinstance(value, _Variable)
)


class BaseConfig(metaclass=_ConfigMeta):
Expand Down
Loading
Loading