Skip to main content

A Black Magic for support obj.__assign__ method

Project description

# Assign

---------

`assign` is a black magic module for supporting `obj.__assign__`:

### How to use it:

#### 1. magic patch

Suppose that there is a `test.py`

```python

a = 1


class T():
def __assign__(self, v):
print('called with %s' % v)


b = T()
c = b

```
It just works as:

```python
Python 3.6.0 (default, Mar 6 2017, 15:44:48)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import magic
>>> import test
called with c

```

#### 2. manually patch

```
from assign.patch import patch_module
import test

patch_module(test)

```

### Install

just:

`pip install assign`

### Notes

* Tested with `Py2.7` and `Py3.6`

### Known Issues

* 1. Won't work under `REPL`
* 2. May slow import operation.
* 3. May failed when patch some modules like `os` and `sys`

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

assign-1.0.1.tar.gz (3.0 kB view details)

Uploaded Source

File details

Details for the file assign-1.0.1.tar.gz.

File metadata

  • Download URL: assign-1.0.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for assign-1.0.1.tar.gz
Algorithm Hash digest
SHA256 fd2019d9686e3595f287eb671e337fc9bccac14857307c446317e88aa46b8bf5
MD5 34478ca8e20dcbe8574d9c8f617e761a
BLAKE2b-256 e6d6a888ae6f85f4caeac23e3190dc659e977d4b8073d6dd82f4ed1a6ed73d33

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