https://github.com/aweirddev/definitely
Definitely typed. Type any object to any type as you wish.
https://github.com/aweirddev/definitely
definitely-typed python-typing typing
Last synced: 6 months ago
JSON representation
Definitely typed. Type any object to any type as you wish.
- Host: GitHub
- URL: https://github.com/aweirddev/definitely
- Owner: AWeirdDev
- License: mit
- Created: 2024-08-16T10:06:50.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-16T11:07:16.000Z (over 1 year ago)
- Last Synced: 2025-07-15T12:02:05.685Z (6 months ago)
- Topics: definitely-typed, python-typing, typing
- Language: Python
- Homepage:
- Size: 5.86 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.
```haskell
pip install definitely-typed
```
I should all be responsible about this, admittedly. Sorry guys.
## Methods
They just exist!
### def definitely
Definitely typed.
```python
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.
```python
# 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.
```python
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.
```python
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