Aliases with correct capitalization for built-in Python types.
Project description
btypes
Aliases with correct capitalization for built-in Python types.
PEP8 states that classes should have names in CamelCase.
However, all the built-in types are lower case: str
, bool
, int
, float
, list
, dict
, etc.
This library provides aliases for all these types that are capitalized correctly.
They are straightforward aliases and can be used exactly like the original types.
Install
Requires Python 3.9+.
pip install btypes
Examples
from btypes import Int, List, Str
def comma_list(lst: List[Int]) -> Str:
return ", ".join(Str(e) for e in lst)
def range_list(limit: Int) -> List[Int]:
return List(range(limit))
Also works with pattern matching:
from btypes import Bool, Str, Union
def print_type(x: Union[Bool, Str]) -> None:
match x:
case Bool():
print("a boolean")
case Str():
print("a string")
FAQs
Why require Python 3.9 as the minimum version?
Because Python 3.9 introduced generic collections in the standard library: list[int]
, dict[str, float]
;
and the whole point of btypes
is that you can use the same identifier as constructor and as type annotation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file btypes-4.1.1.tar.gz
.
File metadata
- Download URL: btypes-4.1.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.7.11 Linux/5.15.15-76051515-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e714a134667e49a6f149f076ead3925c92018ea43ce6c251954444fd7cf6afd2 |
|
MD5 | c450844e7fea00982b4b0a4b55696c1d |
|
BLAKE2b-256 | fd8bc6ff683fd24c064243da895379212642c5ce3124ad2563cbdc89850ae843 |
File details
Details for the file btypes-4.1.1-py3-none-any.whl
.
File metadata
- Download URL: btypes-4.1.1-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.7.11 Linux/5.15.15-76051515-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15609ea6fbee4c3c6ff1bdf2461b038075999ebecaed228b5683fd72f053b03b |
|
MD5 | 226dc5ab1c7215b027211c95cee2a202 |
|
BLAKE2b-256 | f585382a0c8494e12b5a7e701a059764e6ae55564717ba0f0fd5604aa12f8316 |