Skip to content

Commit a06a7e9

Browse files
Adrian AcalaAdrian Acala
Adrian Acala
authored and
Adrian Acala
committed
Update CHANGELOG and fix mypy compatibility for curry.partial
- Added a bugfix entry in CHANGELOG for `curry.partial` compatibility with mypy 1.6.1+. - Modified `inference.py` to use a local variable for argument inference context. - Added mypy configuration file and a test for `partial` functionality in `test_partial.py`.
1 parent a8ffc54 commit a06a7e9

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ incremental in minor, bugfixes only are patches.
66
See [0Ver](https://0ver.org/).
77

88

9+
## Unreleased
10+
11+
### Bugfixes
12+
13+
- Fixes the `curry.partial` compatibility with mypy 1.6.1+
14+
15+
916
## 0.25.0
1017

1118
### Features

returns/contrib/mypy/_typeops/inference.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,15 @@ def _infer_constraints(
8282
self._fallback.arg_names,
8383
lambda index: checker.accept(exprs[index]),
8484
)
85+
86+
arg_context = checker.argument_infer_context()
8587
constraints = infer_constraints_for_callable(
8688
self._fallback,
8789
arg_types=[arg.type for arg in applied_args],
8890
arg_kinds=kinds,
8991
arg_names=[arg.name for arg in applied_args],
9092
formal_to_actual=formal_to_actual,
91-
context=checker.argument_infer_context(),
93+
context=arg_context,
9294
)
9395
return {
9496
constraint.type_var: constraint.target for constraint in constraints

test_partial/mypy.ini

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[mypy]
2+
python_version = 3.11
3+
plugins = returns.contrib.mypy.returns_plugin

test_partial/test_partial.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from returns.curry import partial
2+
3+
4+
def foo(x, bar=None):
5+
"""Add bar to x if bar is provided, otherwise return x."""
6+
return x + bar if bar else x
7+
8+
9+
my_partial = partial(foo, bar=1)
10+
# Type checking: reveal_type(my_partial)

0 commit comments

Comments
 (0)