Repository: numba/numba
Pull request: Fix example and docs typos for `objmode` context manager.
As title.

Fixes #3575

<!--

Thanks for wanting to contribute to Numba :)

First, if you need some help or want to chat to the core developers, please
visit https://gitter.im/numba/numba for real time chat or post to the Numba
mailing list https://groups.google.com/a/continuum.io/forum/#!forum/numba-users.

Here's some guidelines to help the review process go smoothly.

0. Please write a description in this text box of the changes that are being
   made.

1. Please ensure that you have written units tests for the changes made/features
   added.

2. If you are closing an issue please use one of the automatic closing words as
   noted here: https://help.github.com/articles/closing-issues-using-keywords/

3. If your pull request is not ready for review but you want to make use of the
   continuous integration testing facilities please label it with `[WIP]` and
   then remove the label when you'd like it to be reviewed.

4. Once review has taken place please do not add features or make changes out of
   the scope of those requested by the reviewer (doing this just add delays as
   already reviewed code ends up having to be re-reviewed/it is hard to tell
   what is new etc!). Further, please do not rebase your branch on master/force
   push/rewrite history, doing any of these causes the context of any comments
   made by reviewers to be lost. If conflicts occur against master they should
   be resolved by merging master into the branch used for making the pull
   request.

Many thanks in advance for your cooperation!

-->


Problem statement:
Error in documentation of numba.objmode context manager
I was trying to play with the new context manager that should allow executing python code in a compiled (nopython-) numba function and was surprised to find that the example in the documentation did not run. Here is a fixed version:

```
import numpy as np
from numba import njit, objmode

def bar(x):
    # This code is executed by the interpreter.
    return np.asarray(list(reversed(x.tolist())))

@njit
def foo():
    x = np.arange(5)
    with objmode(x='intp[:]'):  # annotate return type
        # this region is executed by object-mode.
        x += bar(x)
    return x

foo()
```
I changed all variable names `y` to `x` (in three places) and I added a closing bracket to the `bar` function body.

Hints from issue discussion:

Commit message: Fix example and docs typos for `objmode` context manager.

As title.

Fixes #3575

Patch to review:
diff --git a/numba/withcontexts.py b/numba/withcontexts.py
index afc5831fb37..effe9c9fd23 100644
--- a/numba/withcontexts.py
+++ b/numba/withcontexts.py
@@ -120,15 +120,15 @@ def mutate_with_body(self, func_ir, blocks, blk_start, blk_end,
 class _ObjModeContextType(WithContext):
     """Creates a contextmanager to be used inside jitted functions to enter
     *object-mode* for using interpreter features.  The body of the with-context
-    is lifted into a function that is compiled into *object-mode*.  This
-    transformation process is limitated and cannot process all possible
+    is lifted into a function that is compiled in *object-mode*.  This
+    transformation process is limited and cannot process all possible
     Python code.  However, users can wrap complicated logic in another
     Python function, which will then be executed by the interpreter.
 
     Use this as a function that takes keyword arguments only.
     The argument names must correspond to the output variables from the
     with-block.  Their respective values are strings representing the expected
-    types.  When exiting the with-context, the output variables are casted
+    types.  When exiting the with-context, the output variables are cast
     to the expected nopython types according to the annotation.  This process
     is the same as passing Python objects into arguments of a nopython
     function.
@@ -140,20 +140,20 @@ class _ObjModeContextType(WithContext):
 
         def bar(x):
             # This code is executed by the interpreter.
-            return np.asarray(list(reversed(x.tolist()))
+            return np.asarray(list(reversed(x.tolist())))
 
         @njit
         def foo():
-            x = np.arange(5)
+            y = np.arange(5)
             with objmode(y='intp[:]'):  # annotate return type
                 # this region is executed by object-mode.
-                y += bar(x)
+                y += bar(y)
             return y
 
-    .. note:: Known limitation:
+    .. note:: Known limitations:
 
-        - with-block cannot use incoming list object.
-        - with-block cannot use incoming function object.
+        - with-block cannot use incoming list objects.
+        - with-block cannot use incoming function objects.
         - with-block cannot ``yield``, ``break``, ``return`` or ``raise`` \
           such that the execution will leave the with-block immediately.
         - with-block cannot contain `with` statements.


Code review comments:
diff_hunk: @@ -140,20 +140,20 @@ class _ObjModeContextType(WithContext):
 
         def bar(x):
             # This code is executed by the interpreter.
-            return np.asarray(list(reversed(x.tolist()))
+            return np.asarray(list(reversed(x.tolist())))
 
         @njit
         def foo():
-            x = np.arange(5)
+            y = np.arange(5)
path: numba/withcontexts.py
text: @user1:
We should change it so that we allocate `y = np.zeros_like(x)` and leave `x` as is.  We want to show that input arrays do not need to be annotated.

@author:
Ah yes, thanks, fixed in eacd307