Skip to main content

This module helps you to get rid of recursions when you wantto rename a builtin function, or a function that already exists.

Project description

This module helps you to get rid of recursions when you want to rename a builtin function, or a function that already exists.

usage:

from no_recursion import no_recursion, replace

@no_recursion
@replace(bin)
def bin(n: int):
    return bin(n)

The decorator replace must be below no_recursion.

it will replace each recursive call to bin with a call to the "original" bin.

You can also set a namespace where it will try to find the original function in,

the original function must be named the same as the decorated function.

You can specify a particular namespace in @no_recursion.

from no_recursion import no_recursion, replace

@no_recursion(vars(__builtins__))
def bin(n: int):
    return bin(n)

In this example, it will take the builtin bin.

The namespace must be a dict that contains the function.

You can also use decorated_f.replace (not the global replace function) to set a replacement function.

import builtins
from no_recursion import no_recursion, replace


@no_recursion
def bin(n: int):
    return bin(n)


@bin.replace
def replace_bin(n: int):
    return builtins.bin(n)

All examples above will produce the same result.

print(bin(12))
# 0b1100

NOTES:

when you call no_recursion with parentheses, you must specify a namespace (@no_recursion({}). Otherwise just do @no_recursion. Exception can be raised.

The decorator replace must be below no_recursion.

In the namespace dictionary, the original function must be named the same as the decorated function.

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

no-recursion-1.0.3.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

no_recursion-1.0.3-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file no-recursion-1.0.3.tar.gz.

File metadata

  • Download URL: no-recursion-1.0.3.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.4

File hashes

Hashes for no-recursion-1.0.3.tar.gz
Algorithm Hash digest
SHA256 36a06ae2d3ae0c1fb9c23aed3e48a987968ddfed51ca1f7209362c659ddba904
MD5 5b98709c1edf49d9ce237f77db521cc5
BLAKE2b-256 1e2aab5dcb395f44b00da599fb8fe8cfe64650ffb165d0c05867cf5941a2262c

See more details on using hashes here.

File details

Details for the file no_recursion-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: no_recursion-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.4

File hashes

Hashes for no_recursion-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4a3559de663ef83d9786e40063621b8fd3b67dee1c91754a57e1543419bb0807
MD5 d9e4b58f9a8aa1b164a53ab9bb83b518
BLAKE2b-256 1ae13393d240db1447c4d9c78829bd3061f7919d21cd72118298c144a26cf264

See more details on using hashes here.

Supported by

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