<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Sat, Sep 8, 2018 at 4:17 AM Jonathan Fine <<a href="mailto:jfine2358@gmail.com">jfine2358@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I thank Steve D'Aprano for pointing me to this real-life (although<br>
perhaps extreme) code example<br>
<br>
<a href="https://github.com/Tinche/aiofiles/blob/master/aiofiles/threadpool/__init__.py#L17-L37" rel="noreferrer" target="_blank">https://github.com/Tinche/aiofiles/blob/master/aiofiles/threadpool/__init__.py#L17-L37</a></blockquote><div><br></div><div>It's hard to know from just a brief glance how the "private" _open function will be used. Using GitHub's repo search, it looks like it's only called once and only in this module. Since it has essentially the same signature as the "public" open function, why not just use *args and **kwds for the private _open?</div><div><br></div><div>Here's a quick refactor that emphasizes the pass-through relationship of open and _open:</div><div><br></div><div><div>    def open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None,</div><div>             closefd=True, opener=None, *, loop=None, executor=None):</div><div>        return AiofilesContextManager(_open(**locals()))</div><div><br></div><div>    @asyncio.coroutine</div><div>    def _open(file, *args, **kwds):</div><div>        """Open an asyncio file."""</div><div>        executor = kwds.pop('executor')</div><div>        loop = kwds.pop('loop')</div><div>        if loop is None:</div><div>            loop = asyncio.get_event_loop()</div><div>            </div><div>        callback = partial(sync_open, file, *args, **kwds)</div><div>        f = yield from loop.run_in_executor(executor, callback)</div><div>        return wrap(f, loop=loop, executor=executor)</div></div><div><br></div><div><br></div><div>I normally dislike the use of **locals(), but here it helps make explicit that the "public" open function passes all arguments through to its helper.</div><div><br></div><div><br></div><div><br></div></div></div>