Skip to content

Commit

Permalink
Make VersionedProperty errors i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
ayjayt committed Jun 6, 2024
1 parent 014a591 commit 723a6e4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pozo/drawable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import pozo.themes as pzt
import warnings

from pozo.utils.language import _d
from pozo.utils.language import _d, _
from pozo.utils.docs import doc
# VersionProperty is a python "descriptor", it allows us to create class variables but define how they behave when they are set, accessed, and declared. See drawable for how to use it.
class VersionedProperty:
def __set_name__(self, owner, name):
if type(owner) != str(Drawable):
raise AttributeError(f"{name} must be a member of a class inheriting pozo.drawable.Drawable, not {owner}. Is type {type(owner)}.")
raise AttributeError(_("%s must be a member of a class inheriting pozo.drawable.Drawable, not %s. Is type %s.") % (name, owner, str(type(owner))))
self._private_name = "_" + name
self._name = name

Expand All @@ -17,7 +17,7 @@ def __get_certain__(self, obj, version):

def __get__(self, obj, objtype=None):
if obj is None:
return AttributeError(f"{self._name} can only be accessed from instantiated ojects, not classes")
return AttributeError(_("%s can only be accessed from instantiated ojects, not classes") % self._name)
return getattr(obj, self._private_name)[obj.version]

def __set__(self, obj, value):
Expand All @@ -30,7 +30,7 @@ def __set__(self, obj, value):
temp[obj.version] = value

def __delete__(self, obj):
raise AttributeError(f"Can't delete {self._name}, please use {obj.__name__}.remove_version().")
raise AttributeError(_("Can't delete %s, please use %s.remove_version().") % (self._name, obj.__name__))

def new_version(self, obj, copy=True, deep=True, index=-1):
if deep: copy = False
Expand All @@ -47,7 +47,7 @@ def new_version(self, obj, copy=True, deep=True, index=-1):
else:
temp.insert(index, None)
if deep or copy:
warnings.warn(f"{self._name} was asked for a copy but it contains no native .copy() method, new version is None")
warnings.warn(_("%s was asked for a copy but it contains no native .copy() method, new version is None") % self._name)

def remove_version(self, obj, version):
temp = getattr(obj, self._private_name, None)
Expand Down

0 comments on commit 723a6e4

Please sign in to comment.