Skip to content

Commit 59cd2fb

Browse files
authored
Update Result
### Breaking - Dropped Python 3.8 & 3.9 to simplify maintenance ### Features - Added Python 3.13 - Added support for `@as_generator_result` and `@as_async_generator_result`, which function like `@as_result` but wrap the yield values of a generator - Allow bubbling up unwrapping of nested `Result` inside the `@as_*` decorated classes. If you unwrap an `Err` of an exception type that you handle in the generator, it will return that `Err(Exception)`from the decorated function as if you had thrown the Exception directly. ### Fixes - Switch to a uv build system with hatch - Switched linter to Ruff - Updated the links to point to forked repo
2 parents 0b855e1 + 80ead86 commit 59cd2fb

File tree

19 files changed

+1336
-436
lines changed

19 files changed

+1336
-436
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
on:
33
push:
44
branches:
5-
- main
5+
# - main
66
pull_request:
77

88
name: CI
@@ -14,67 +14,27 @@ jobs:
1414
strategy:
1515
matrix:
1616
python:
17+
- '3.13'
1718
- '3.12'
1819
- '3.11'
1920
- '3.10'
20-
- '3.9'
21-
- '3.8'
2221
name: Python ${{ matrix.python }}
2322
steps:
24-
# Python
25-
- name: Setup python ${{ matrix.python }}
26-
uses: actions/setup-python@v2
23+
- uses: actions/checkout@v4
24+
- name: Install the latest version of uv and set the python version
25+
uses: astral-sh/setup-uv@v5
2726
with:
2827
python-version: ${{ matrix.python }}
29-
30-
# Check out code
31-
- uses: actions/checkout@v2
32-
33-
# Cached dependencies
34-
- uses: actions/cache@v1
35-
with:
36-
path: ~/.cache/pip
37-
key: ${{ runner.os }}-pip-py${{ matrix.python }}-${{ hashFiles('**/requirements-dev.txt') }}
38-
restore-keys: |
39-
${{ runner.os }}-pip-py${{ matrix.python }}-
40-
- name: Install dev dependencies
41-
# There's no virtual env in CI environment, just bypass it with a dummy
42-
# env var value
43-
run: VIRTUAL_ENV=none make install
44-
45-
# Tests
46-
- name: Run tests
47-
run: pytest --ignore=tests/test_pattern_matching.py --ignore=tests/type_checking/test_result.yml
48-
- name: Run tests (type checking)
49-
if: matrix.python != '3.8' && matrix.python != '3.9'
50-
# These started breaking for <= 3.9, due to the type checker using a
51-
# '|' for unions rather than 'Union[...]', so it's not possible to run
52-
# the tests without maintaining two duplicate files (one for <= 3.9 and
53-
# one for > 3.9)
54-
run: pytest tests/type_checking/test_result.yml
55-
- name: Run tests (pattern matching)
56-
if: matrix.python == '3.10' || matrix.python == '3.11' || matrix.python == '3.12'
57-
run: pytest tests/test_pattern_matching.py
58-
59-
# Linters
60-
- name: Run flake8 (Python >= 3.10)
61-
run: make lint-flake
62-
if: matrix.python != '3.9' && matrix.python != '3.8'
63-
- name: Run flake8 (Python < 3.10)
64-
run: make lint-flake-pre310
65-
if: matrix.python == '3.9' || matrix.python == '3.8'
66-
- name: Run mypy
67-
run: make lint-mypy
28+
29+
# Quality
30+
- name: Test with python ${{ matrix.python }}
31+
run: uv run --frozen pytest
32+
- name: Lint
33+
run: make lint
34+
- name: Type check
35+
run: make type-check
6836

6937
# Packaging
7038
- name: Build packages
71-
run: |
72-
pip install --upgrade build pip setuptools wheel
73-
python -m build
39+
run: uv build
7440

75-
# Coverage
76-
- name: Upload coverage to codecov.io
77-
uses: codecov/codecov-action@v1
78-
if: matrix.python == '3.9'
79-
with:
80-
token: ${{ secrets.CODECOV_TOKEN }}

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

CHANGELOG.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# Changelog
22

3-
This project follows semantic versioning.
3+
## [Unreleased]
44

5-
Possible log types:
5+
### Breaking
6+
- Dropped Python 3.8 & 3.9 to simplify maintenance
67

7-
- `[added]` for new features.
8-
- `[changed]` for changes in existing functionality.
9-
- `[deprecated]` for once-stable features removed in upcoming releases.
10-
- `[removed]` for deprecated features removed in this release.
11-
- `[fixed]` for any bug fixes.
12-
- `[security]` to invite users to upgrade in case of vulnerabilities.
8+
### Features
9+
- Added Python 3.13
10+
- Added support for `@as_generator_result` and `@as_async_generator_result`, which function like `@as_result` but wrap the yield values of a generator
11+
- Allow bubbling up unwrapping of nested `Result` inside the `@as_*` decorated classes. If you unwrap an `Err` of an exception type that you handle in the generator, it will return that `Err(Exception)`from the decorated function as if you had thrown the Exception directly.
1312

14-
## [Unreleased]
13+
### Fixes
14+
- Switch to a uv build system with hatch
15+
- Switched linter to Ruff
16+
- Updated the links to point to forked repo
17+
18+
## [0.18.0.dev0] - Unreleased, Forked from Upstream
1519

1620
- `[changed]` Improve type narrowing for `is_ok` and `is_err` type guards by
1721
replacing `typing.TypeGuard` with `typing.TypeIs` (#193)

MANIFEST.in

Lines changed: 0 additions & 1 deletion
This file was deleted.

Makefile

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,19 @@
22
.PHONY: phony
33

44
install: phony
5-
ifndef VIRTUAL_ENV
6-
$(error install can only be run inside a Python virtual environment)
7-
endif
8-
@echo Installing dependencies...
9-
pip install -r requirements-dev.txt
10-
pip install -e .
5+
uv sync
116

12-
lint: phony lint-flake lint-mypy
7+
lint: phony
8+
uv run ruff check .
139

14-
lint-flake: phony
15-
flake8
16-
17-
lint-flake-pre310: phony
18-
# Python <3.10 doesn't support pattern matching.
19-
flake8 --extend-exclude tests/test_pattern_matching.py
20-
21-
lint-mypy: phony
22-
mypy
10+
type-check: phony
11+
uv run mypy
2312

2413
test: phony
25-
pytest
14+
uv run pytest
2615

2716
docs: phony
28-
lazydocs \
17+
uv run --python 3.10 lazydocs \
2918
--overview-file README.md \
30-
--src-base-url https://github.com/rustedpy/result/blob/main/ \
19+
--src-base-url https://github.com/montasaurus/result/blob/main/ \
3120
./src/result

README.md

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
# Result
22

3-
[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/rustedpy/result/ci.yml?branch=main)](https://github.com/rustedpy/result/actions/workflows/ci.yml?query=branch%3Amain)
4-
[![Coverage](https://codecov.io/gh/rustedpy/result/branch/main/graph/badge.svg)](https://codecov.io/gh/rustedpy/result)
5-
63
A simple Result type for Python 3 [inspired by
74
Rust](https://doc.rust-lang.org/std/result/), fully type annotated.
85

9-
## Installation
10-
11-
Latest release:
6+
> [!WARNING]
7+
> Forked from the original [result](https://github.com/rustedpy/result) library after it became unmaintained. This version is experimental and mainly used for my own projects--use it at your own risk!
128
13-
``` sh
14-
$ pip install result
15-
```
9+
## Installation
1610

1711
Latest GitHub `main` branch version:
1812

1913
``` sh
20-
$ pip install git+https://github.com/rustedpy/result
14+
uv add git+https://github.com/montasaurus/result
2115
```
2216

2317
## Summary
@@ -422,29 +416,6 @@ Sometimes regular `do()` can handle async values, but this error means
422416
you have hit a case where it does not. You should use `do_async()` here
423417
instead.
424418

425-
## Contributing
426-
427-
These steps should work on any Unix-based system (Linux, macOS, etc) with Python
428-
and `make` installed. On Windows, you will need to refer to the Python
429-
documentation (linked below) and reference the `Makefile` for commands to run
430-
from the non-unix shell you're using on Windows.
431-
432-
1. Setup and activate a virtual environment. See [Python docs][pydocs-venv] for more
433-
information about virtual environments and setup.
434-
2. Run `make install` to install dependencies
435-
3. Switch to a new git branch and make your changes
436-
4. Test your changes:
437-
- `make test`
438-
- `make lint`
439-
- You can also start a Python REPL and import `result`
440-
5. Update documentation
441-
- Edit any relevant docstrings, markdown files
442-
- Run `make docs`
443-
6. Add an entry to the [changelog](./CHANGELOG.md)
444-
5. Git commit all your changes and create a new PR.
445-
446-
[pydocs-venv]: https://docs.python.org/3/library/venv.html
447-
448419
## FAQ
449420

450421
- **Why should I use the `is_ok` (`is_err`) type guard function over the `is_ok` (`is_err`) method?**

RELEASING.md

Lines changed: 0 additions & 51 deletions
This file was deleted.

codecov.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

docs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
## Functions
1717

18+
- [`result.as_async_generator_result`](./result.md#function-as_async_generator_result)
1819
- [`result.as_async_result`](./result.md#function-as_async_result): Make a decorator to turn an async function into one that returns a ``Result``.
20+
- [`result.as_generator_result`](./result.md#function-as_generator_result)
1921
- [`result.as_result`](./result.md#function-as_result): Make a decorator to turn a function into one that returns a ``Result``.
2022
- [`result.do`](./result.md#function-do): Do notation for Result (syntactic sugar for sequence of `and_then()` calls).
2123
- [`result.do_async`](./result.md#function-do_async): Async version of do. Example:

0 commit comments

Comments
 (0)