Skip to main content

Typed Null support

Project description

nullable

Typed Null support

import typing as t
from dataclasses import dataclass

from nullable import Null, NullType, Nullable, NullableNoneOr

# valid typehints:
val: int | NullType = Null
val: Nullable[int] = Null

val: int | None | NullType = Null
val: NullableNoneOr[int] = Null

# example usage:
@dataclass
class Settings:
    is_cool: bool
    countdown: t.Optional[int]

    def alter(
        self,
        *,
        is_cool: Nullable[bool] = Null,
        countdown: NullableNoneOr[int] = Null,
    ) -> None:
        if is_cool is not Null:
            self.is_cool = is_cool
        if countdown is not Null:
            self.countdown = countdown

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

nullable-0.2.0.tar.gz (1.8 kB view hashes)

Uploaded Source

Built Distribution

nullable-0.2.0-py3-none-any.whl (2.4 kB view hashes)

Uploaded Python 3

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