Repository: python/mypy

Issue:
Extra space in generated Python code
The code

```
void f(str na):
    pass
```

gets translated into

```
def f( na):
    pass
```

There should not a space before `na`. 

Note that if `na` is replaced with `n`, the extra space is no longer generated.

Extra space in generated Python code
The code

```
void f(str na):
    pass
```

gets translated into

```
def f( na):
    pass
```

There should not a space before `na`. 

Note that if `na` is replaced with `n`, the extra space is no longer generated.



Discussion:

Resolving patch:
diff --git a/build.py b/build.py
--- a/build.py
+++ b/build.py
@@ -166,6 +166,7 @@ class BuildResult:
         # Add library stubs directory. By convention, they are stored in the
         # stubs directory of the mypy implementation.
         path.append(os.path.join(mypy_base_dir, 'stubs'))
+        path.append(os.path.join(mypy_base_dir, 'stubs-auto'))
     
     # Add fallback path that can be used if we have a broken installation.
     if sys.platform != 'win32':
@@ -457,11 +458,12 @@ class BuildManager:
     Currently check if there is a 'stubs' directory component somewhere
     in the path."""
     # TODO more precise check
-    if os.path.basename(path) == '':
+    dirname, basename = os.path.split(path)
+    if basename == '':
         return False
     else:
-        return os.path.basename(path) == 'stubs' or is_stub(
-            os.path.dirname(path))
+        stubnames = ['stubs', 'stubs-auto']
+        return (basename in stubnames) or is_stub(dirname)
 
 
 # State ids. These describe the states a source file / module can be in a
diff --git a/output.py b/output.py
--- a/output.py
+++ b/output.py
@@ -139,7 +139,7 @@ def function_header(self, o, arg_repr, arg_kinds, pre_args_func=None,
                     # Remove spaces before the first argument name. Generally
                     # spaces are only present after a type, and if we erase the
                     # type, we should also erase also the spaces.
-                    n = re.sub(' +([a-zA-Z0-9_])$', '\\1', n)
+                    n = re.sub(' +([a-zA-Z0-9_]+)$', '\\1', n)
                 self.string(n)
             if i < len(arg_repr.assigns):
                 self.token(arg_repr.assigns[i])
diff --git a/testconfig.py b/testconfig.py
--- a/testconfig.py
+++ b/testconfig.py
@@ -5,5 +5,11 @@
 # Location of test data files such as test case descriptions.
 test_data_prefix = os.path.join(PREFIX, 'test', 'data')
 
+assert os.path.isdir(test_data_prefix), \
+        'Test data prefix ({}) not set correctly'.format(test_data_prefix)
+
 # Temp directory used for the temp files created when running test cases.
 test_temp_dir = os.path.join(PREFIX, 'tmp')
+
+assert os.path.isdir(test_temp_dir), \
+        'Test temp dir ({}) not set correctly'.format(test_temp_dir)


Test patch:
diff --git a/test/data/pythongen.test b/test/data/pythongen.test
--- a/test/data/pythongen.test
+++ b/test/data/pythongen.test
@@ -619,3 +619,14 @@ def g(x):
         return g2(x)
     else:
         raise TypeError("Invalid argument types")
+
+[case testNoSpaceBeforeFirstArg]
+-- Issue #34
+class A: pass
+void f(A na):
+    pass
+[out]
+class A: pass
+def f(na):
+    pass
+