Skip to content

Commit

Permalink
Changed backing attributes to private.
Browse files Browse the repository at this point in the history
  • Loading branch information
sg495 committed Jan 16, 2024
1 parent 218ad4f commit 0a71d95
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 68 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
# built documents.
#
# The full version, including alpha/beta/rc tags.
release = "1.0.0"
release = "1.1.0"
# The short X.Y version.
version = "1.0.0"
version = "1.1.0"


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion test/test_00_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_base_set_name_slots(attr_name: Optional[str]) -> None:
if attr_name is not None:
slot_name = attr_name
else:
slot_name = "_x"
slot_name = "__x"
class C:
x = Attr(int, lambda _, x: x >= 0, attr_name=attr_name)
__slots__ = (slot_name,)
Expand Down
18 changes: 2 additions & 16 deletions typed_descriptors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,13 @@
Descriptor classes with static and runtime validation features.
"""

# typed-descriptors: Descriptor classes for typed attributes and properties.
# Copyright (C) 2023 Hashberg Ltd

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.

# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA

from __future__ import annotations
from .attr import Attr
from .prop import Prop

__version__ = "1.0.0"
__version__ = "1.1.0"

__all__ = ("Attr", "Prop")
16 changes: 1 addition & 15 deletions typed_descriptors/attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,9 @@
Descriptor class for attributes.
"""

# Part of typed-descriptors
# Copyright (C) 2023 Hashberg Ltd

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.

# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA

from __future__ import annotations
import sys
from typing import (
Expand Down
25 changes: 6 additions & 19 deletions typed_descriptors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,16 @@
Abstract base class for descriptors backed by protected/private attributes.
"""

# Part of typed-descriptors
# Copyright (C) 2023 Hashberg Ltd

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.

# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA

from __future__ import annotations
from abc import abstractmethod
import sys
from typing import (
Any,
Generic,
Literal,
MutableSequence,
Optional,
Type,
TypeVar,
Expand All @@ -52,8 +37,9 @@ class DescriptorBase(Generic[T]):
- if the optional kwarg ``attr_name`` is specified in the constructor,
the descriptor uses an attribute with that given name
- otherwise, the descriptor uses an attribute obtained from the
descriptor name by prepending an underscore
- otherwise, the descriptor uses a private attribute obtained from the
descriptor name by prepending one or two underscores (depending on
whether the descriptor name itself starts with underscore or not, resp.).
If the attribute name starts with two underscores but does not end with
two underscores, name-mangling is automatically performed.
Expand Down Expand Up @@ -186,7 +172,8 @@ def __set_name__(self, owner: Type[Any], name: str) -> None:
# 2. Get the backing attribute name (not yet name-mangled):
given_attr_name = self.__given_attr_name
if given_attr_name is None:
given_attr_name = f"_{name}"
attr_name_prefix = "_" if name.startswith("_") else "__"
given_attr_name = f"{attr_name_prefix}{name}"
elif given_attr_name == name:
raise ValueError(
f"Name of backing attribute for descriptor {self.name!r} "
Expand Down
16 changes: 1 addition & 15 deletions typed_descriptors/prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,9 @@
Descriptor class for cached properties.
"""

# Part of typed-descriptors
# Copyright (C) 2023 Hashberg Ltd

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.

# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA

from __future__ import annotations
import sys
from typing import (
Expand Down

0 comments on commit 0a71d95

Please sign in to comment.