This package add a callable descriptor called method descriptor which can apply on methods.
Project description
fancy-descriptors
This package adds a callable descriptor called method descriptor which can apply to methods.
Usage
a simplest example:
import fancy.descriptor as fd
class MyDescriptor(fd.MethodDescriptor):
pass
class MyClass:
@MyDescriptor
def method_a(self):
pass
# or
@MyDescriptor.bind()
def method_b(self):
pass
# after a MyClass object is created.
my_obj = MyClass()
assert isinstance(my_obj.method_a, MyDescriptor)
# returned {"method_a": <MyDescriptor object>, "method_b": <MyDescriptor object>}
MyDescriptor.get_marked_method(my_obj)
the statement MyDescriptor.get_marked_method(my_obj) will get all marked methods' descriptors
with metadata
import fancy.descriptor as fd
class MyDescriptor(fd.MethodDescriptor):
def __init__(self,method, value: int, factory = None):
"""
method must at first place of argument
factory is a method descriptor factory for underlying descriptor
"""
super().__init__(method, factory)
self._value = value
def get_value(self):
return self._value
class MyClass:
# you cannot directly use MyDescriptor as decorator
# if the constructor of the descriptor has over one required argument
# you must use .bind() to instead.
@MyDescriptor.bind(value=1)
def method_annotated(self):
pass
my_obj = MyClass()
my_obj.method_annotated.get_value() # returned 1
Inheritance
import fancy.descriptor as fd
class MyBaseDescriptor(fd.MethodDescriptor):
pass
class MyDescriptor(MyBaseDescriptor):
pass
class MyClass:
@MyBaseDescriptor
def method_base(self):
pass
@MyDescriptor
def method_sub(self):
pass
my_obj = MyClass()
MyBaseDescriptor.get_marked_method(my_obj) # returned both method_base and method_sub
MyDescriptor.get_marked_method(my_obj) # returned only method_sub
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fancy-descriptor-1.2.0a2.tar.gz.
File metadata
- Download URL: fancy-descriptor-1.2.0a2.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41f6f4bfa0e68f7fbb5652447ed445b9130f3230c1c415bbbdddd7d31a1f4a1c
|
|
| MD5 |
1c12d16d0f2761056d6c8ac36e531371
|
|
| BLAKE2b-256 |
b184e650d244e8f8a121d1cfc88b3c3393597d3ea27b90bdb9422188872ce289
|
File details
Details for the file fancy_descriptor-1.2.0a2-py3-none-any.whl.
File metadata
- Download URL: fancy_descriptor-1.2.0a2-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d11a9f6b3a7ae17ec93d689048bba5db9bb724785bed88da38926b9f11daeb7b
|
|
| MD5 |
a3aff10e230ff554d02c64d0c955efa5
|
|
| BLAKE2b-256 |
38819b56f9e3c2eb4f8ca468bcf3f172450995bc2d4f027297ec3fca57fc3767
|