Release/v0.4.1 #1

Merged
rus07tam merged 12 commits from release/v0.4.1 into main 2025-10-27 15:05:33 +03:00
Showing only changes of commit 737f21bf06 - Show all commits

View file

@ -1,27 +1,32 @@
from typing import Any, Callable
from snakia.utils import throw
class Readonly[T]:
from .property import Property
class Readonly[T](Property[T]):
"""
codacy-production[bot] commented 2025-10-27 15:04:50 +03:00 (Migrated from github.com)

🚫 Codacy found a high ErrorProne issue: invalid syntax (F999)

The issue arises from the use of generics in the class definition. The syntax Readonly[T](Property[T]) is incorrect in Python, as the use of generics requires the Generic base class from the typing module. To fix this, you need to inherit from Generic[T] in addition to Property[T].

Here's the code suggestion to fix the issue:

class Readonly(Property[T], Generic[T]):

This comment was generated by an experimental AI tool.

:no_entry_sign: **Codacy** found a **high ErrorProne** issue: [invalid syntax (F999)](https://app.codacy.com/gh/RuJect/snakia/pull-requests/1) The issue arises from the use of generics in the class definition. The syntax `Readonly[T](Property[T])` is incorrect in Python, as the use of generics requires the `Generic` base class from the `typing` module. To fix this, you need to inherit from `Generic[T]` in addition to `Property[T]`. Here's the code suggestion to fix the issue: ```suggestion class Readonly(Property[T], Generic[T]): ``` --- *This comment was generated by an experimental AI tool.*
Readonly property.
"""
__slots__ = ("__fget",)
def __init__(
self,
fget: Callable[[Any], T],
*,
strict: bool = False,
) -> None:
self.__fget = fget
def __get__(self, instance: Any, owner: type | None = None, /) -> T:
return self.__fget(instance)
def __set__(self, instance: Any, value: T, /) -> None:
pass
super().__init__(
fget=fget,
fset=(
(lambda *_: throw(TypeError("Cannot set readonly property")))
if strict
else lambda *_: None
),
)
def readonly[T](value: T) -> Readonly[T]:
def readonly[T](value: T, *, strict: bool = False) -> Readonly[T]:
"""Create a readonly property with the given value.
Args:
@ -30,4 +35,4 @@ def readonly[T](value: T) -> Readonly[T]:
Returns:
Readonly[T]: The readonly property.
"""
return Readonly(lambda _: value)
return Readonly(lambda _: value, strict=strict)