Skip to content

Commit d6a1b11

Browse files
Merge pull request #211 from nucleic/fixed-tuple
Add FixedTuple member enforcing a given number of items
2 parents 330b8fc + fb808da commit d6a1b11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+472
-201
lines changed

.coveragerc

Lines changed: 0 additions & 19 deletions
This file was deleted.

.flake8

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ jobs:
105105
uses: actions/setup-python@v4
106106
with:
107107
python-version: ${{ matrix.python-version }}
108-
cache: 'pip'
109-
cache-dependency-path: 'test_requirements.txt'
110108
- name: Install dependencies
111109
run: |
112110
python -m pip install --upgrade pip
@@ -119,11 +117,9 @@ jobs:
119117
run: |
120118
pip install -e .
121119
- name: Test with pytest
122-
# XXX Disabled warnings check ( -W error) to be able to test on 3.11
123-
# (pyparsing deprecation)
124120
run: |
125121
pip install -r test_requirements.txt
126-
python -X dev -m pytest tests --ignore=tests/type_checking --cov --cov-report xml -v
122+
python -X dev -m pytest tests --ignore=tests/type_checking --cov --cov-report xml -v -W error
127123
- name: Generate C++ coverage reports
128124
if: (github.event_name != 'schedule' && matrix.os != 'windows-latest')
129125
run: |

atom/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
#
66
# The full license is in the file LICENSE, distributed with this software.
77
# --------------------------------------------------------------------------------------
8-
"""Module exporting the public interface to atom.
8+
"""Module exporting the public interface to atom."""
99

10-
"""
1110
from .atom import Atom
1211
from .catom import (
1312
CAtom,
@@ -61,7 +60,7 @@
6160
from .set import Set
6261
from .signal import Signal
6362
from .subclass import ForwardSubclass, Subclass
64-
from .tuple import Tuple
63+
from .tuple import FixedTuple, Tuple
6564
from .typed import ForwardTyped, Typed
6665
from .typing_utils import ChangeDict
6766

@@ -120,5 +119,6 @@
120119
"Tuple",
121120
"ForwardTyped",
122121
"Typed",
122+
"FixedTuple",
123123
"ChangeDict",
124124
]

atom/catom.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ class Validate(IntEnum):
537537
Dict = ...
538538
DefaultDict = ...
539539
Enum = ...
540+
FixedTuple = ...
540541
Float = ...
541542
FloatPromote = ...
542543
FloatRange = ...

atom/meta/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# The full license is in the file LICENSE, distributed with this software.
77
# --------------------------------------------------------------------------------------
88
"""Atom metaclass and tools used to create atom subclasses."""
9+
910
from .atom_meta import AtomMeta, MissingMemberWarning, add_member, clone_if_needed
1011
from .member_modifiers import set_default
1112
from .observation import observe

atom/meta/annotation_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ..scalars import Bool, Bytes, Callable as ACallable, Float, Int, Str, Value
1717
from ..set import Set as ASet
1818
from ..subclass import Subclass
19-
from ..tuple import Tuple as ATuple
19+
from ..tuple import FixedTuple, Tuple as ATuple
2020
from ..typed import Typed
2121
from ..typing_utils import extract_types, get_args, is_optional
2222
from .member_modifiers import set_default
@@ -71,10 +71,10 @@ def generate_member_from_type_or_generic(
7171
):
7272
# We can only validate homogeneous tuple so far so we ignore other cases
7373
if t is tuple:
74-
if (...) in parameters or len(set(parameters)) == 1:
74+
if (...) in parameters:
7575
parameters = (parameters[0],)
7676
else:
77-
parameters = ()
77+
m_cls = FixedTuple
7878
parameters = tuple(
7979
generate_member_from_type_or_generic(
8080
t, _NO_DEFAULT, annotate_type_containers - 1

atom/meta/atom_meta.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# The full license is in the file LICENSE, distributed with this software.
77
# --------------------------------------------------------------------------------------
88
"""Metaclass implementing atom members customization."""
9+
910
import copyreg
1011
import warnings
1112
from types import FunctionType

atom/meta/member_modifiers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# The full license is in the file LICENSE, distributed with this software.
77
# --------------------------------------------------------------------------------------
88
"""Custom marker objects used to modify the default settings of a member."""
9+
910
from typing import Any, Optional
1011

1112

@@ -28,3 +29,9 @@ def __init__(self, value: Any) -> None:
2829
def clone(self) -> "set_default":
2930
"""Create a clone of the sentinel."""
3031
return type(self)(self.value)
32+
33+
34+
# XXX add more sentinels here to allow customizing members without using the
35+
# members themselves:
36+
# - tag
37+
#

atom/meta/observation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# The full license is in the file LICENSE, distributed with this software.
77
# --------------------------------------------------------------------------------------
88
"""Tools to declare static observers in Atom subclasses"""
9+
910
from types import FunctionType
1011
from typing import (
1112
TYPE_CHECKING,

0 commit comments

Comments
 (0)