Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions packages/typemap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Changelog

All notable changes to this project will be documented in this file.

## [0.2.0] - 2026-03-05

### Added

- **KeyOf[T]** - Returns all member names as a tuple of Literal types
- Similar to TypeScript's `keyof` operator
- Example: `KeyOf[User]` returns `tuple[Literal["name"], Literal["age"]]`

- **Template[*Parts]** - Template literal string builder
- Concatenates string literal types at runtime
- Example: `Template["api/v1/", Literal["users"]]` returns `Literal["api/v1/users"]`

- **DeepPartial[T]** - Make all fields recursively optional
- Applies optional transformation to all nested types
- Example: `DeepPartial[User]` makes all nested fields optional

- **Partial[T]** - Make all fields optional (non-recursive)
- Makes all top-level fields optional without recursion
- Example: `Partial[User]` returns `name: str | None, age: int | None`

- **Required[T]** - Remove Optional from all fields
- Inverse operation of Partial
- Example: `Required[OptionalUser]` removes `| None` from all fields

- **Pick[T, K]** - Pick specific fields from a type
- Creates a new type with only the specified fields
- Example: `Pick[User, tuple["name", "email"]]`

- **Omit[T, K]** - Omit specific fields from a type
- Creates a new type excluding specified fields
- Example: `Omit[User, tuple["password"]]`

### Changed

- Updated `typemap_extensions` to export all new type utilities

## [0.1.2] - 2026-03-04

### Added

- Initial release with core type evaluation
- Support for PEP 827 type manipulation
- `eval_typing` function for runtime type evaluation
- Core type operators: Member, Attrs, Iter, Param, UpdateClass, NewProtocol, IsAssignable
48 changes: 48 additions & 0 deletions packages/typemap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ typemap provides utilities for working with [PEP 827](https://peps.python.org/pe
- `UpdateClass` - Generate class modifications
- `NewProtocol` - Create protocols dynamically
- `IsAssignable` - Check type assignability
- `KeyOf` - Get all member names as tuple of Literals
- `Template` - Build template literal strings
- `DeepPartial` - Make all fields recursively optional
- `Partial` - Make all fields optional (non-recursive)
- `Required` - Remove Optional from all fields
- `Pick` - Pick specific fields from a type
- `Omit` - Omit specific fields from a type

## Usage

Expand All @@ -37,6 +44,47 @@ result = eval_typing(MyClass)
print(result)
```

### Type Utilities

typemap provides several type utility operators for transforming types:

```python
from typing import Literal
import typemap_extensions as tm

# KeyOf - Get all member names as tuple of Literals
class User:
name: str
age: int

keys = tm.KeyOf[User]
# Result: tuple[Literal["name"], Literal["age"]]

# Partial - Make all fields optional (non-recursive)
PartialUser = tm.Partial[User]
# Result: class with name: str | None, age: int | None

# DeepPartial - Make all fields recursively optional
DeepUser = tm.DeepPartial[User]
# Result: class with all nested fields optional

# Required - Remove Optional from all fields
class OptionalUser:
name: str | None
age: int | None

RequiredUser = tm.Required[OptionalUser]
# Result: class with name: str, age: int

# Pick - Select specific fields
PublicUser = tm.Pick[User, tuple["name"]]
# Result: class with only name: str

# Omit - Exclude specific fields
SafeUser = tm.Omit[User, tuple["password"]]
# Result: class without password field
```

### Using UpdateClass

```python
Expand Down
2 changes: 1 addition & 1 deletion packages/typemap/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "typemap"
version = "0.1.2"
version = "0.2.0"
description = "PEP 827 type manipulation library"
requires-python = ">=3.14"
dependencies = [
Expand Down
Loading