Skip to content

Commit

Permalink
refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
kaliv0 committed Sep 17, 2024
1 parent 4d0ad8a commit 6ec9a1c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
22 changes: 9 additions & 13 deletions pypermissive/decorators.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
class ComputedField:
class ComputedClassField:
def __init__(self, func):
self.__func = func
self._func = func
self.__name__ = func.__name__

def __get__(self, instance, owner):
if instance is None:
if owner is None:
return None
result = self.__func(instance)
setattr(instance, self.__name__, result)
result = self._func(owner)
setattr(owner, self.__name__, result)
return result


class ComputedClassField:
def __init__(self, func):
self.__func = func
self.__name__ = func.__name__

class ComputedField(ComputedClassField):
def __get__(self, instance, owner):
if owner is None:
if instance is None:
return None
result = self.__func(owner)
setattr(owner, self.__name__, result)
result = self._func(instance)
setattr(instance, self.__name__, result)
return result


Expand Down
3 changes: 2 additions & 1 deletion pypermissive/field.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Callable
from collections.abc import Callable
from typing import Any
from dataclasses import dataclass


Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import itertools
import random
from enum import Enum
from typing import List
from uuid import UUID, uuid4

from pypermissive import BaseModel, Field, ComputedField, ComputedClassField, validate_call
Expand All @@ -22,7 +21,7 @@ class Employee(BaseModel):


class Boy(BaseModel):
hobbies: List[str] = ["Football"]
hobbies: list[str] = ["Football"]


class Education(BaseModel):
Expand Down

0 comments on commit 6ec9a1c

Please sign in to comment.