suned / pfun

Functional, composable, asynchronous, type-safe Python.
https://pfun.dev/
MIT License
151 stars 14 forks source link

mypy plugin error: 'tuple' object does not support item assignment #62

Closed hugosenari closed 3 years ago

hugosenari commented 4 years ago

Probably something I'm doing wrong (ie not informing types arguments of Either), but...

mypy MethodContext.default_return_type.args may return a tuple instead of a list.

Raising ''TypeError: 'tuple' object does not support item assignment" for code above

return_type = context.default_return_type
return_type_args: return_type.args
...
return_type_args[0]: _combine_environments(r1, r2)

We could expect that if isn't a list dev made something wrong - like I did - but this and similar assignments may cause unintended side effects :thinking:

suned commented 3 years ago

Did you ever find the reproducing example? I tried e: Either but did not resolve in the described error. It would be great to have a test case before this is merged.

hugosenari commented 3 years ago

Can you try this please, is the minimal example I could found.

from pfun.either import catch

@catch
def hello_world() -> str:
    return 'Hello World'

At least here it returns:

/home/hugosenari/.local/share/virtualenvs/my_test-tjBmjRl0/lib/python3.8/site-packages/pfun/effect.py:458: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.800
Traceback (most recent call last):
  File "mypy/checkexpr.py", line 3898, in accept
  File "mypy/nodes.py", line 1555, in accept
  File "mypy/checkexpr.py", line 270, in visit_call_expr
  File "mypy/checkexpr.py", line 347, in visit_call_expr_inner
  File "mypy/checkexpr.py", line 852, in check_call_expr_with_callee_type
  File "mypy/checkexpr.py", line 911, in check_call
  File "mypy/checkexpr.py", line 1023, in check_callable_call
  File "mypy/checkexpr.py", line 732, in apply_function_plugin
  File "/home/hugosenari/.local/share/virtualenvs/my_test-tjBmjRl0/lib/python3.8/site-packages/pfun/mypy_plugin.py", line 433, in _effect_recover_hook
    return_type_args[0] = _combine_environments(r1, r2)
TypeError: 'tuple' object does not support item assignment
/home/hugosenari/.local/share/virtualenvs/my_test-tjBmjRl0/lib/python3.8/site-packages/pfun/effect.py:458: : note: use --pdb to drop into pdb