Giter VIP home page Giter VIP logo

btypes's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.