Skip to main content

definitely

Typing tricks that make your type checker a little more quiet.

Key features:

  • definitely – Type everything as you wish.
  • asyncily – Run a function asynchronously.
  • asyncily_iterate – Iterate through an iterator asynchronously.
  • reversely – Reverse a dictionary.
pip install definitely-typed

I should all be responsible about this, admittedly. Sorry guys.

Methods

They just exist!

def definitely

Definitely typed.

person = "Charles"

# Transforms `person` into any type you desire
assert definitely(person, int)

reveal_type(person)
#           ^^^^^^
# runtime:     str
# typecheck:   int

The runtime type WILL NOT change, yet when TYPE_CHECKING, the variable acts just like the desired type (in this case, int).

def asyncily

Asynchronously run a function.

# You can use this as a decorator like so:
@asyncily
def buy_stuff(item: str):
    print("dad is going out!")
    time.sleep(2 << 40)
    print("came back with the %s!" % item)

await buy_stuff("milk")

# Or, you can use this as a "async function factory" like so:
def make(name: str):
    return f"Made product: {name!r}"

amake = asyncily(make)
await amake("milk")

def asyncily_iterate

Asynchronously iterate through an iterator.

def get_resources():
    yield from ["banana", "guava", "apple"]

async for resource in asyncily_iterate(get_resources()):
    print("-", resource)

# Output:
# - banana
# - guava
# - apple

def reversely

Reverse a dictionary.

metadata = {"password": 1234, "total_users": 100_000}
reversed_metadata = reversely(metadata)

assert reversed_metadata == {1234: "password", 100_000: "users"}

reveal_type(reversed_metadata)
#           ^^^^^^^^^^^^^^^^^
# runtime:     dict[int, str]
# typecheck:   dict[str, int]

(c) 2024 AWeirdDev, and other silly people

Metadata

Release files for definitely-typed 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for definitely-typed 0.2
File Size Uploaded Provenance
definitely_typed-0.2.tar.gz 4.5 kB Without provenance Details

Release files / definitely_typed-0.2.tar.gz

Download URL definitely_typed-0.2.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a6970ff8ee56827119f4e50aa3891196c6a4f3f7a96fc6540faa5586432af21e
BLAKE2b-256 checksum
How to use checksums
6b8e6316b08fbc2b034a1dd2ceabad77eae91224973f49c57b6e3e1e06079992
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Security for definitely-typed 0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page