Skip to content

Commit 0b4b8cb

Browse files
committed
Refactors
1 parent cf36f26 commit 0b4b8cb

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ def bad_function() -> Optional[int]:
237237
...
238238

239239
maybe_result: Maybe[float] = Maybe.new(
240-
bad_function(),
240+
bad_function(),
241241
).map(
242-
lambda number: number / 2
242+
lambda number: number / 2,
243243
)
244244
# => Maybe will return Some(float) only if there's a non-None value
245245
# Otherwise, will return Nothing

returns/contrib/mypy/decorator_plugin.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@
3131

3232

3333
def _change_decorator_function_type(
34-
decorated: CallableType,
3534
decorator: CallableType,
35+
arg_type: CallableType,
3636
) -> CallableType:
3737
"""Replaces revealed argument types by mypy with types from decorated."""
38-
decorator.arg_types = decorated.arg_types
39-
decorator.arg_kinds = decorated.arg_kinds
40-
decorator.arg_names = decorated.arg_names
41-
return decorator
38+
return decorator.copy_modified(
39+
arg_types=arg_type.arg_types,
40+
arg_kinds=arg_type.arg_kinds,
41+
arg_names=arg_type.arg_names,
42+
variables=arg_type.variables,
43+
is_ellipsis_args=arg_type.is_ellipsis_args,
44+
)
4245

4346

4447
def _analyze_decorator(function_ctx: FunctionContext):
@@ -48,8 +51,8 @@ def _analyze_decorator(function_ctx: FunctionContext):
4851
if not isinstance(function_ctx.default_return_type, CallableType):
4952
return function_ctx.default_return_type
5053
return _change_decorator_function_type(
51-
function_ctx.arg_types[0][0],
5254
function_ctx.default_return_type,
55+
function_ctx.arg_types[0][0],
5356
)
5457

5558

0 commit comments

Comments
 (0)