Skip to main content

Improved abstraction for dealing with union and named types.

Project description

slightly-better-types

... arguably

Improved abstraction for dealing with union and named types.

Installation

pip install slightly-better-types==0.0.1

Usage

Using the Function class:

from slightly_better_types.function import Function


def accepts_string(a: str, b: int):
    pass


sb_function = Function(accepts_string)

sb_function.accepts('string', 1)  # True
sb_function.accepts(1, 'string')  # False
sb_function.accepts('string')  # False

Using Handlers to determine which methods accept a given set of input:

from slightly_better_types.handlers import Handlers


class Bar:
    def accepts_string(self, a: str):
        pass

    def accepts_string_too(self, a: str):
        pass

    def accepts_int(self, a: int):
        pass


handlers = Handlers(Bar)
list(handlers.accepts('a string').all().keys())  # ['accepts_string', 'accepts_string_too']
list(handlers.accepts(1).first().get_name())  # 'accepts_int'

Tests

python3 -m unittest

License

The MIT License (MIT). Please see License File for more information.

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

slightly-better-types-0.0.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

slightly_better_types-0.0.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file slightly-better-types-0.0.1.tar.gz.

File metadata

  • Download URL: slightly-better-types-0.0.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for slightly-better-types-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5e334201d9a2b8751eda397a26928a268bee2e55a5dc777d7277579891af389c
MD5 d061c769ab935bb3f90caaca4b9b0e9d
BLAKE2b-256 027375c739949a588f328ce7a8e4b23fdddffb6e21a23e9af7120e3486ca6efc

See more details on using hashes here.

File details

Details for the file slightly_better_types-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for slightly_better_types-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 34c58152aefde6466e1b9f8146a3160255885297ba7fd661f069aadb8d657d19
MD5 84a56ed5a1e1de2c5d834d525fa8609a
BLAKE2b-256 0ad55ce15c9246c21652744f8470b4b2fc1812319d56e48758b208c0af33a4d6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page