<p dir="auto">I'm trying to implement some automatic MPI &lt;-&gt; NumPy datatype conversion for to enhance mpi4py. Users usually struggle to get it right from complex types, mostly because NumPy defaults to packed structs, while MPI defaults to aligned structs. I'm stuck with an minor issue. I guess it is related Python 2 legacy from the time we had to use an <code class="notranslate">L</code> suffix to write long integers. Minimal reproducer and proposed fix in the following.</p>
<h3 dir="auto">Reproducing code example:</h3>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
np.dtype(&quot;3L&quot;)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-s1">np</span>.<span class="pl-en">dtype</span>(<span class="pl-s">"3L"</span>)</pre></div>
<h3 dir="auto">Error message:</h3>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/usr/lib64/python3.7/site-packages/numpy/core/_internal.py&quot;, line 199, in _commastring
    newitem = (dtype, eval(repeats))
  File &quot;&lt;string&gt;&quot;, line 1
    3L
     ^
SyntaxError: unexpected EOF while parsing"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/usr/lib64/python3.7/site-packages/numpy/core/_internal.py", line 199, in _commastring
    newitem = (dtype, eval(repeats))
  File "&lt;string&gt;", line 1
    3L
     ^
SyntaxError: unexpected EOF while parsing
</code></pre></div>
<h3 dir="auto">Numpy/Python version information:</h3>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="1.16.3 3.7.3 (default, May 11 2019, 00:38:04) 
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]"><pre class="notranslate"><code class="notranslate">1.16.3 3.7.3 (default, May 11 2019, 00:38:04) 
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]
</code></pre></div>
<h3 dir="auto">Proposed trivial fix (tested)</h3>
<div class="highlight highlight-source-diff notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index ab5a64a1a..c70718cb6 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -146,7 +146,7 @@ def _reconstruct(subtype, shape, dtype):
 # format_re was originally from numarray by J. Todd Miller
 
 format_re = re.compile(br'(?P&lt;order1&gt;[&lt;&gt;|=]?)'
-                       br'(?P&lt;repeats&gt; *[(]?[ ,0-9L]*[)]? *)'
+                       br'(?P&lt;repeats&gt; *[(]?[ ,0-9]*[)]? *)'
                        br'(?P&lt;order2&gt;[&lt;&gt;|=]?)'
                        br'(?P&lt;dtype&gt;[A-Za-z0-9.?]*(?:\[[a-zA-Z0-9,.]+\])?)')
 sep_re = re.compile(br'\s*,\s*')"><pre class="notranslate"><span class="pl-c1">diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py</span>
index ab5a64a1a..c70718cb6 100644
<span class="pl-md">--- a/numpy/core/_internal.py</span>
<span class="pl-mi1">+++ b/numpy/core/_internal.py</span>
<span class="pl-mdr">@@ -146,7 +146,7 @@</span> def _reconstruct(subtype, shape, dtype):
 # format_re was originally from numarray by J. Todd Miller
 
 format_re = re.compile(br'(?P&lt;order1&gt;[&lt;&gt;|=]?)'
<span class="pl-md"><span class="pl-md">-</span>                       br'(?P&lt;repeats&gt; *[(]?[ ,0-9L]*[)]? *)'</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>                       br'(?P&lt;repeats&gt; *[(]?[ ,0-9]*[)]? *)'</span>
                        br'(?P&lt;order2&gt;[&lt;&gt;|=]?)'
                        br'(?P&lt;dtype&gt;[A-Za-z0-9.?]*(?:\[[a-zA-Z0-9,.]+\])?)')
 sep_re = re.compile(br'\s*,\s*')</pre></div>
<p dir="auto">the title says it all.</p>
<p dir="auto">additional info:<br>
python: 2.7.9, numpy: 1.9.2, both from conda.<br>
other combinations not using 'L' seems to work fine.</p>