Skip to main content

fonc

multiline inline anonymous functions in python

>>> from fonc import fonc
>>> [
...     fonc("""
... def x(input): # doesn't matter what this function is called
...     value = input * 3.14
...     return int(value)
...     """)(value) for value in [1, 2, 3, 4]
... ]
[3, 6, 9, 12]

why would you do this terrible thing

:) :) :) :) :) :) :) :) :) :) :) :)

does this pollute my global namespace?

nope!

imagine this inline function:

>>> from fonc import fonc
>>> [
...     fonc("""
... def x(input): # doesn't matter what this function is called
...     value = input * 3.14
...     return int(value)
...     """)(value) for value in [1, 2, 3, 4]
... ]
[3, 6, 9, 12]

One might imagine that this means that the x function name is overwritten to the global namespace. It is not!

>>> x(1)
NameError: name 'x' is not defined

how this works pls?

  • parse the string and determine the name of the defined function
  • replace that with a known random value
  • replace calls to that inline function with calls to the renamed function

never-asked questions

  • Do I have access to global vars inside this function?

    ya

  • Can I use this in production?

    absolutely not u fool

Metadata

Release files for fonc 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fonc 0.2.0
File Size Uploaded
fonc-0.2.0.tar.gz 3.2 kB Details

Release files / fonc-0.2.0.tar.gz

Download URL fonc-0.2.0.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
adb8db15011583e11deeafaa0903978011d16b0f77f5eef3c1fbc4182aac16c7
BLAKE2b-256 checksum
How to use checksums
e084f66194c6dc810052193a76360e087625f83dde1712ca966337f7ee471fd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page