# AutoProperty library

## What it used for?

This library is used for creating autogenerated properties with type validation.

I wrote this library for my own uses and points. I think it is very comfy to use and less code to write.  

I just have enough of writting millions and trillions of "@property" decorators and setters for them. It also have type validation, a bonus.

## How does this work?

Basically it is just a common **property** or **data descriptor** (if you feel better to call it like that) but instead of storing the providing **private** (optionally) class attribute inside itself, it creating the attribute inside the autoproperty containing class instance. 

You **do not need** to do anything - only smoke the cigarrete, throw legs on a table and rest. Let it do all hard and boring work. You are the **king** and you **deserve** no other treatment.

Jokes aside, it do all hard work, let me show you.

## Usage

### Syntax

Base syntax.

```python
class Exmpl:
    @AutoProperty[int] # <-- need for correct syntax highlighting
    def SomeProp(self, v: int): ... # <-- no need to implement, it won't change anything
                        # ^ type annotation for checking object in setter
```

In runtime it turns construction above to a construction like below:

```python
class Exmpl:
    __someProp: int

    @AutoProperty[int]
    def SomeProp(self, v: int): ...
```

---

### Annotations

You **have to** add annotation on any of three places

```python
class Exmpl:
    __someProp: int # <-- one

    @AutoProperty[int](annotationType=int) # <-- two
    def SomeProp(self, v: int): ...
    #                     ^ three (will read only first parameter after self)
```

---

### Access

By default autoproperty has private access:

```python
class Exmpl:
    @AutoProperty[int]
    def SomeProp(self, v: int): ...

    def __init__(self):
        self.SomeProp = 42 # ok

example = Exmpl()
print(example.SomeProp) # Error: UnaccessiblePropertyMethod
```

CSharp analogy:

```cs
class Exmpl(){
    private int SomeProp { get; set; }

    Exmpl(){
        this.SomeProp = 42; // ok
    }
} 

Exmpl example = new();
_ = example.SomeProp; // Error: CS0271
```

>I dont know how to fix it but even python debugger in VSCode cant go against it, if you do know please open an issue and **tell me**. I'll appreciate that.


## Full example

```python
from autoproperty import AutoProperty


class Point:
    def __init__(self, x: int, y: int):
        self.X = x
        self.Y = y

    # by default it has private access
    @AutoProperty[int](access_mod="public", s_access_mod="private")
    def X(self, v: int): ...

    @AutoProperty[int](access_mod="public", s_access_mod="private")
    def Y(self, v: int): ...

    def __repr__(self) -> str:
        return f"[{self.X};{self.Y}]"
        #               ^        ^ is ok

myPointOne = Point(2, 6)

myPointOne.X = 5 # Error: UnaccessiblePropertyMethod

print(myPointOne.X) # ok

print(myPointOne) # [2; 6]
```

## Known problems

- Not working correct while inheriting from class with private autoproperty using super().\_\_init\_\_() or any other method or object from parent class due not enough information.
- Not tested yet with classmethods or staticmethods, only bound methods

## Feedback

If you want to ask me something, you have solution one of the above problems, you have an offer to me or any other reason, please open an issue or message me via email alecsw86@gmail.com.