Skip to content

metaist/castfit

Repository files navigation

castfit: basic type casting

Cuddles the Cat
Cuddles the Cat
"If it fits, I sits."

Build PyPI Supported Python Versions

Why?

I'm writing more and more type-checked code, but I often get a bunch of strings I need to convert (e.g., from docopt).

Install

python -m pip install castfit

Alternatively, you can just download the single file and name it castfit.py.

Example

from pathlib import Path
from castfit import castfit

class Cat:
  name: str
  age: int
  weight: float
  logo: Path

bob = castfit(Cat, dict(name="Bob", age="4", weight="3.2", logo="./bob.png"))
assert bob.name == "Bob"
assert bob.age == 4
assert bob.weight == 3.2
assert bob.logo == Path("./bob.png")

License

MIT License