Skip to main content

No project description provided

Project description

Panyc

Super simple python package to solve 2 problems:

  • In Python assert is not guaranteed to work (see the -O flag)
  • The very convenient todo()/unreachable()/... functions to panic in case reached, are missing

Usage

from panyc import raise_if

def is_even(x):
	raise_if(type(x) != int, f"expected an integer, got {type(x)}")
	return x % 2 == 0

def main():
	x = 6.9
	print("Is", x, "even?", is_even(x))

main()

Will result in AssertionError: /path/to/file/example.py:4: expected an integer, got <class 'float'>

A couple of notice:

  • first of all the condition must be true to raise, in the contrary of assert where it must be false
  • secondly it raise an AssertionError as well, so the error handling remain the same

So if you plan to rewrite your asserts you have to change the condition and nothing else

from panyc import todo

def end_world_hungry():
	todo()

def main():
	end_world_hungry()

main()

Will result in NotImplementedError: /path/to/file/example.py:4: Function "end_world_hungry" not implemented

from panyc import unreachable

def sound(x):
	if x == "cat":
		return "meow"
	elif x == "dog":
		return "woof"
	elif x == "duck":
		return "quack"
	unreachable() # we do not expect other animals

def main():
	print(sound("crocodile"))

main()

Will result in NotImplementedError: /path/to/file/example.py:10: Reached unreachable code in "sound"

Installation

Just copy the only file panyc.py in your project.

If you like the slop, there's also the package on pypi:

$ pip install panyc

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

panyc-1.0.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

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

panyc-1.0.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: panyc-1.0.0.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for panyc-1.0.0.tar.gz
Algorithm Hash digest
SHA256 67084af566e6667d38e408e7daf637e37bb816deced97247a688346170aec268
MD5 95b9632c71bdfdf8319fc19da7d448ef
BLAKE2b-256 0a7d4f58e57ed8e174748f60d0adb78dfd88e72dcc1a9f57f5d15126d615bb14

See more details on using hashes here.

File details

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

File metadata

  • Download URL: panyc-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for panyc-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c09c495ea2d8d3f1a316282fbe2309381867eecb5f62d1aa21a7604aa0ccbc81
MD5 c9600b47b764b474e461eb278057bf99
BLAKE2b-256 7d7a28fe73867551185b07f18515cd3c5fcdd04bbd0eab479c4e99286316f1fc

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