Skip to content

add MultiError.__init__ to avoid linter confusion - #1067

Merged
njsmith merged 1 commit into
python-trio:masterfrom
belm0:multi_error_init
Jun 4, 2019
Merged

njsmith merged 1 commit into
python-trio:masterfrom
belm0:multi_error_init

Conversation

@belm0

@belm0 belm0 commented May 28, 2019 •

Copy link
Copy Markdown
Member

Fixes #1066

@belm0
belm0 requested a review from njsmith May 28, 2019 02:25
@njsmith

njsmith commented May 28, 2019

Copy link
Copy Markdown
Member
=================================== FAILURES ===================================
______________________ test_system_task_crash_MultiError _______________________
    def test_system_task_crash_MultiError():
        async def crasher1():
            raise KeyError
    
        async def crasher2():
            raise ValueError
    
        async def system_task():
            async with _core.open_nursery() as nursery:
                nursery.start_soon(crasher1)
                nursery.start_soon(crasher2)
    
        async def main():
            _core.spawn_system_task(system_task)
            await sleep_forever()
    
        with pytest.raises(_core.TrioInternalError) as excinfo:
            _core.run(main)
    
        me = excinfo.value.__cause__
        assert isinstance(me, _core.MultiError)
>       assert len(me.exceptions) == 2
E       assert 1 == 2
E         -1
E         +2
../../../../virtualenv/python3.6-dev/lib/python3.6/site-packages/trio/_core/tests/test_run.py:1062: AssertionError

A news fragmnet would be appropriate too.

@belm0

belm0 commented May 28, 2019 •

Copy link
Copy Markdown
Member Author

I'm baffled by the test failure. Somehow the exceptions field contains a MultiError instance, which itself contains a MultiError instance, until it hits a recursion limit.

Why only this particular test?

@oremanj

oremanj commented May 29, 2019

Copy link
Copy Markdown
Member

@belm0 Looks like you're running into the fact that Python calls __init__ on the object returned by __new__ if it's of the type that the __new__ was called on. So let's say you have

assert type(e) is MultiError
assert e.exceptions == [a, b]

and you say MultiError([e]). There's only one exception there, so MultiError.__new__([e]) returns e. But that's itself a MultiError, so its __init__ gets called, setting e.exceptions = [e].

I think this might be more trouble than it's worth to fix before MultiError v2 / ExceptionGroup arrives.

@belm0
belm0 force-pushed the multi_error_init branch from 4202864 to dd6c7c6 Compare May 29, 2019 23:57
@belm0

belm0 commented May 30, 2019

Copy link
Copy Markdown
Member Author

Only an error in Python 3.8 now, but seems unrelated other that it's coming from the file to which I added a test.

_______________ ERROR collecting _core/tests/test_multierror.py ________________
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/trio/_core/tests/test_multierror.py:660: in <module>
    import IPython
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/IPython/__init__.py:55: in <module>
    from .terminal.embed import embed
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/IPython/terminal/embed.py:15: in <module>
    from IPython.core.interactiveshell import DummyMod, InteractiveShell
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/IPython/core/interactiveshell.py:339: in <module>
    class InteractiveShell(SingletonConfigurable):
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/IPython/core/interactiveshell.py:2909: in InteractiveShell
    def run_cell_async(self, raw_cell: str, store_history=False, silent=False, shell_futures=True) -> ExecutionResult:
/opt/python/3.8-dev/lib/python3.8/asyncio/coroutines.py:111: in coroutine
    warnings.warn('"@coroutine" decorator is deprecated since Python 3.8, use "async def" instead',
E   DeprecationWarning: "@coroutine" decorator is d

Comment thread trio/_core/_multierror.py Resolved
Comment thread trio/_core/_multierror.py Resolved
@njsmith

njsmith commented Jun 2, 2019

Copy link
Copy Markdown
Member

(And the test failure will be fixed by #1076)

add explicit test for MultiError([MultiError()])
@belm0
belm0 force-pushed the multi_error_init branch from dd6c7c6 to 3a95a97 Compare June 3, 2019 12:15
@codecov

codecov Bot commented Jun 3, 2019

Copy link
Copy Markdown

Codecov Report

Merging #1067 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #1067      +/-   ##
==========================================
+ Coverage   99.53%   99.53%   +<.01%     
==========================================
  Files         102      102              
  Lines       12318    12324       +6     
  Branches      922      923       +1     
==========================================
+ Hits        12261    12267       +6     
  Misses         36       36              
  Partials       21       21
Impacted Files Coverage Δ
trio/_core/_multierror.py 100% <100%> (ø) ⬆️
trio/_core/tests/test_multierror.py 100% <100%> (ø) ⬆️
trio/_core/tests/test_run.py 100% <0%> (ø) ⬆️

@codecov

codecov Bot commented Jun 3, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #1067 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #1067      +/-   ##
==========================================
+ Coverage   99.53%   99.53%   +<.01%     
==========================================
  Files         102      102              
  Lines       12318    12327       +9     
  Branches      922      923       +1     
==========================================
+ Hits        12261    12270       +9     
  Misses         36       36              
  Partials       21       21
Impacted Files Coverage Δ
trio/_core/_multierror.py 100% <100%> (ø) ⬆️
trio/_core/tests/test_multierror.py 100% <100%> (ø) ⬆️

@njsmith

njsmith commented Jun 4, 2019

Copy link
Copy Markdown
Member

Looks great, thanks!

@njsmith
njsmith merged commit 2e628fc into python-trio:master Jun 4, 2019
@belm0
belm0 deleted the multi_error_init branch October 1, 2020 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MultiError.exceptions foils linter

3 participants