Repository: python/mypy

Issue:
Configuration file recognizes dash as correct but results in broken config
mypy doesn't seem to be able to recognize dashed-options as incorrect within the context of a config file.

For example, suppose we have the following files `nothing.py` and `mypy.ini`

```python
def nothing():
    pass
```

```
[mypy]
X = True
```

When `X` is:
- `disallow_untyped_defs`
    - Correctly reports `nothing.py:1: error: Function is missing a type annotation`
- `disallow_untyped_defs1`
    - Correctly reports: `mypy.ini: [mypy]: Unrecognized option: disallow_untyped_defs1 = True`
- `disallow-untyped-defs`
    - Doesn't tell me I'm missing a type annotation, nor that the option is incorrect.  No errors at all!

Python 3.6.4 and mypy 0.570 were used.


Discussion:
Good observation! Can you dig in the source to see what's wrong? Something is presumably normalizing the dashes to underscore, but something else doesn't seem to use the normalized version...

Resolving patch:
diff --git a/mypy/main.py b/mypy/main.py
--- a/mypy/main.py
+++ b/mypy/main.py
@@ -760,8 +760,6 @@ def parse_section(prefix: str, template: Options,
     results = {}  # type: Dict[str, object]
     report_dirs = {}  # type: Dict[str, str]
     for key in section:
-        orig_key = key
-        key = key.replace('-', '_')
         if key in config_types:
             ct = config_types[key]
         else:
@@ -770,9 +768,9 @@ def parse_section(prefix: str, template: Options,
                 if key.endswith('_report'):
                     report_type = key[:-7].replace('_', '-')
                     if report_type in reporter_classes:
-                        report_dirs[report_type] = section[orig_key]
+                        report_dirs[report_type] = section[key]
                     else:
-                        print("%s: Unrecognized report type: %s" % (prefix, orig_key),
+                        print("%s: Unrecognized report type: %s" % (prefix, key),
                               file=sys.stderr)
                     continue
                 if key.startswith('x_'):
@@ -782,7 +780,7 @@ def parse_section(prefix: str, template: Options,
                           "individual flags instead (see 'mypy -h' for the list of flags enabled "
                           "in strict mode)" % prefix, file=sys.stderr)
                 else:
-                    print("%s: Unrecognized option: %s = %s" % (prefix, key, section[orig_key]),
+                    print("%s: Unrecognized option: %s = %s" % (prefix, key, section[key]),
                           file=sys.stderr)
                 continue
             ct = type(dv)


Test patch:
diff --git a/test-data/unit/cmdline.test b/test-data/unit/cmdline.test
--- a/test-data/unit/cmdline.test
+++ b/test-data/unit/cmdline.test
@@ -241,6 +241,18 @@ bad = 0
 mypy.ini: [mypy]: Unrecognized option: bad = 0
 == Return code: 0
 
+[case testConfigErrorBadFlag]
+# cmd: mypy a.py
+[file mypy.ini]
+[[mypy]
+disallow-untyped-defs = True
+[file a.py]
+def f():
+    pass
+[out]
+mypy.ini: [mypy]: Unrecognized option: disallow-untyped-defs = True
+== Return code: 0
+
 [case testConfigErrorBadBoolean]
 # cmd: mypy -c pass
 [file mypy.ini]