Skip to main content

work with annotated but not defined/not used attrs in class

Project description

Ver/TestedPython Ver/Os
repo/Created Commit/Last Tests/GitHubWorkflowStatus Tests/GitHubWorkflowStatus
repo/Size Commit/Count/t Commit/Count/y Commit/Count/m

annot_attrs (current v0.1.0/Ver/Pypi Latest)

DESCRIPTION_SHORT

work with annotated but not defined/not used attrs in class

DESCRIPTION_LONG

Designed to get list of annotated but not defined/not used attrs from class (not instance!).
may be helpful further in instance to check that really have values.

Features

  1. get set of unused attributes from class(not instance!)
  2. work with nested classes
  3. get values:
    • by case insensitive names
    • by dict key access method
  4. work on any object (over Obj parameter!):
    • at least for NamedTuple

License

See the LICENSE file for license rights and limitations (MIT).

Release history

See the HISTORY.md file for release history.

Installation

pip install annot-attrs

Import

from annot_attrs import *

USAGE EXAMPLES

See tests, sourcecode and docstrings for other examples.


1. example1.py

# ===============================================================
### 1. inheritance
# (BEST practice - dont mess classes! use as separated object!)
from annot_attrs import *

class Cls:
    ATTR1: int
    ATTR2: int = 2

obj = Cls(1)

assert AnnotAllDefined().annots_get_set(obj) == {"ATTR1", }
assert AnnotAllDefined().annots_get_dict(obj) == {"ATTR1": 1, }


# ===============================================================
from annot_attrs import *

class Cls(AnnotAllDefined):
    ATTR1: int
    ATTR2: int = 2

assert Cls().annots_get_set() == {"ATTR1", }

class Cls2(Cls):
    ATTR1: int = 2
    ATTR3: int

assert Cls2().annots_get_set() == {"ATTR1", "ATTR3", }

inst = Cls2()
inst.ATTR1 = 1
inst.ATTR2 = 1
inst.ATTR3 = 1

assert Cls2().annots_get_set() == {"ATTR1", "ATTR3", }

assert Cls().ATTR2 == 2
assert Cls().attr2 == 2

assert Cls()["ATTR2"] == 2
assert Cls()["attr2"] == 2

obj = Cls()
try:
    obj.annots_get_dict()
except Exx__AnnotNotDefined:
    pass
else:
    assert False

obj.ATTR1 = 1
assert obj.annots_get_dict() == {"ATTR1": 1}


# ===============================================================
### 2. Indepandant usage
from annot_attrs import *

try:
    class Cls(AnnotAllDefined, NamedTuple):
        ATTR1: int
        ATTR2: int = 2
except TypeError:
    # TypeError: can only inherit from a NamedTuple type and Generic
    pass
else:
    assert True

class Cls(NamedTuple):
    ATTR1: int
    ATTR2: int = 2

obj = Cls(1)
assert AnnotAllDefined().annots_get_set(obj) == {"ATTR1", }
assert AnnotAllDefined().annots_get_dict(obj) == {"ATTR1": 1}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

annot_attrs-0.1.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

annot_attrs-0.1.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file annot_attrs-0.1.0.tar.gz.

File metadata

  • Download URL: annot_attrs-0.1.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for annot_attrs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 564aea43844168f270a3b631a774da3918945add241b44ee2d1e395014cdac09
MD5 461ad6d6d7329635ca2f932968bd9956
BLAKE2b-256 97098837c81191f0d71b8e67e0c62d970ce5288f71f83ebcfa97bb1fd19245cf

See more details on using hashes here.

File details

Details for the file annot_attrs-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: annot_attrs-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for annot_attrs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 98dfdb35151ded75b57d00bf26da4077e0395123868535a9c3b9bd7dc41c6056
MD5 5c2540188cd5be114d9d96fed43078ac
BLAKE2b-256 10263ea3eef998ebf3325761e020026e4a45d735b1cd9f58fb35c949931e3785

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page