Skip to content

Commit

Permalink
rename _data in _valid_values
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrecamilleri committed Jan 28, 2025
1 parent 24cdcfa commit f1438a8
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/frformat/set_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def is_sorted(cls) -> bool:


class SingleSetFormat(CustomStrFormat):
"""This format defines a closed list of valid values."""
"""This format defines a closed list of valid values"""

_data: FrozenSet = frozenset()
_valid_values: FrozenSet = frozenset()
"""Dataset of valid values.
Technical details:
Beware, child classes may define an instance `_data` attribute, which
Beware, child classes may define an instance `_valid_values` attribute, which
will always take precedence over the class attribute for the validation.
"""

Expand All @@ -61,8 +61,8 @@ def __init__(self, options: Options = Options()):

self._normalized_values = {
normalize_value(e, self._options)
for e in self._data
# in child classes, `self._data` can reference an instance
for e in self._valid_values
# in child classes, `self._valid_values` can reference an instance
# attribute, if applicable ; otherwise the class attribute will
# be used
}.union(normalized_extra_values)
Expand All @@ -86,20 +86,20 @@ class VersionedSetFormat(SingleSetFormat, Generic[V]):
Technical details:
- In the versioned set format, the _data attribute is an instance attribute,
- In the versioned set format, the `_valid_values` attribute is an instance attribute,
which takes precedence over the class attribute of the mother class. The
reason for this is that the exact valid values set is only known on instantiation.
"""

_versioned_data: VersionedSet = VersionedSet()
_versioned_valid_values: VersionedSet = VersionedSet()

def __init__(self, version: Union[V, str], options: Options = Options()):
version_id = version if isinstance(version, str) else version.get_id()
data = self._versioned_data.get_data(version_id)
data = self._versioned_valid_values.get_data(version_id)
if data is None:
raise ValueError(f"No data available for version: {version_id}")

self._data = data
self._valid_values = data
super().__init__(options)


Expand Down Expand Up @@ -132,14 +132,14 @@ def new(
if isinstance(valid_data, VersionedSet):

class NewVersionedFormat(VersionedSetFormat):
_versioned_data = valid_data
_versioned_valid_values = valid_data

specialized_set_format = NewVersionedFormat

else:

class NewFormat(SingleSetFormat):
_data = valid_data
_valid_values = valid_data

specialized_set_format = NewFormat

Expand Down

0 comments on commit f1438a8

Please sign in to comment.