Skip to main content

Get the source code string of an expression and optionally evalute it.

Project description

rexpr

A small library that uses Python 3.14's new templates (t-strings) to smoothly implement a way to turn an expression into its source code string dynamically.

Advantages

This solution brings multiple advantages:

  • Laziness: If the expression should does not need to be evaluated (only the source code string is desired), it won't be.
  • Fast: Only very few basic string checks and modifications are performed.
  • Builtin support by type checkers and linters: As long as a type checker / linter supports templates, the correct return value (if evaluated), the correctness of the expression and the correct type of the interpolation can be verified. As of writing this (Python 3.14rc2), generic support for templates and interpolations has been added, but is not yet supported by typeshed and type checkers.
  • Single point of truth: By having the possibility to also evaluate an expression in the same function call, there is no need to duplicate an expression to get both its evaluated value and its source code string.

References

This module is an implementation of the ideas and solutions proposed by my topic.

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

rexpr-1.0.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

rexpr-1.0.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file rexpr-1.0.0.tar.gz.

File metadata

  • Download URL: rexpr-1.0.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0rc2

File hashes

Hashes for rexpr-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d20032cb2bb516cb70a4da3e170e9414485c42861b425a4dce3c8a106eb8afa6
MD5 18b9ed78849d40ae5025ba7a7b6d7418
BLAKE2b-256 2b68305b7b21dd56e1a2bc1c56f624bf07083550b75ce31a10452f682e884801

See more details on using hashes here.

File details

Details for the file rexpr-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: rexpr-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0rc2

File hashes

Hashes for rexpr-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9aa692db0aa48819f43751ceda3192e2c7dbd6c4c62f3d179975e6479220db88
MD5 7d4e12be315f2dfd381c2cafa704bc55
BLAKE2b-256 fd5ccda7601914ac5930ff5b9203c537ad553344307a9486a82dea959d4b4a1e

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