internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: python/mypy

Issue:
Add a note suggesting to add __init__.py in case of duplicate modules
For example:
```
dir/lib.py: error: Duplicate module named 'lib'
dir/lib.py: note: Are you missing '__init__.py'?
```
Probably we should use some heuristic to add this note only when it makes sense (e.g. there is at least one directory level between the file and the place where mypy is running).


Discussion:
working on this


Resolving patch:
diff --git a/mypy/build.py b/mypy/build.py
--- a/mypy/build.py
+++ b/mypy/build.py
@@ -12,15 +12,16 @@
 
 import binascii
 import contextlib
+import errno
 import gc
 import hashlib
 import json
 import os
+import pathlib
 import re
 import stat
 import sys
 import time
-import errno
 import types
 
 from typing import (AbstractSet, Any, Dict, Iterable, Iterator, List,
@@ -2601,6 +2602,15 @@ def load_graph(sources: List[BuildSource], manager: BuildManager,
                 -1, -1,
                 "Duplicate module named '%s' (also at '%s')" % (st.id, graph[st.id].xpath)
             )
+            p1 = len(pathlib.PurePath(st.xpath).parents)
+            p2 = len(pathlib.PurePath(graph[st.id].xpath).parents)
+
+            if p1 != p2:
+                manager.errors.report(
+                    -1, -1,
+                    "Are you missing an __init__.py?"
+                )
+
             manager.errors.raise_error()
         graph[st.id] = st
         new.append(st)


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
@@ -109,6 +109,19 @@ mypy: can't decode file 'a.py': unknown encoding: uft-8
 two/mod/__init__.py: error: Duplicate module named 'mod' (also at 'one/mod/__init__.py')
 == Return code: 2
 
+[case promptsForgotInit]
+# cmd: mypy a.py one/mod/a.py
+[file one/__init__.py]
+# type: ignore
+[file a.py]
+# type: ignore
+[file one/mod/a.py]
+#type: ignore
+[out]
+one/mod/a.py: error: Duplicate module named 'a' (also at 'a.py')
+one/mod/a.py: error: Are you missing an __init__.py?
+== Return code: 2
+
 [case testFlagsFile]
 # cmd: mypy @flagsfile
 [file flagsfile]
Repository: python/mypy

Issue:
Confusing message when missing positional argument
The error message generated for this example is confusing, since only `c` is missing:

```py
def f(a, b, c, d=None) -> None:
    pass

f(1, 2, d=3)  # Missing positional arguments "a", "b", "c" in call to "f"
```


Discussion:
Increased priority since I'm seeing this pretty frequently.
I'm working on this issue.

Resolving patch:
diff --git a/mypy/messages.py b/mypy/messages.py
--- a/mypy/messages.py
+++ b/mypy/messages.py
@@ -644,7 +644,9 @@ def too_few_arguments(self, callee: CallableType, context: Context,
                           argument_names: Optional[Sequence[Optional[str]]]) -> None:
         if (argument_names is not None and not all(k is None for k in argument_names)
                 and len(argument_names) >= 1):
-            diff = [k for k in callee.arg_names if k not in argument_names]
+            num_positional_args = sum(k is None for k in argument_names)
+            arguments_left = callee.arg_names[num_positional_args:]
+            diff = [k for k in arguments_left if k not in argument_names]
             if len(diff) == 1:
                 msg = 'Missing positional argument'
             else:


Test patch:
diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test
--- a/test-data/unit/check-functions.test
+++ b/test-data/unit/check-functions.test
@@ -2328,6 +2328,14 @@ def foo(__b: int, x: int, y: int) -> int: pass
 foo(x=2, y=2)  # E: Missing positional argument
 foo(y=2)  # E: Missing positional arguments
 
+[case testMissingArgumentError]
+def f(a, b, c, d=None) -> None: pass
+f(1, 2, d=3) # E: Missing positional argument "c" in call to "f"
+
+[case testMissingArgumentsError]
+def f(a, b, c, d=None) -> None: pass
+f(1, d=3) # E: Missing positional arguments "b", "c" in call to "f"
+
 [case testReturnTypeLineNumberWithDecorator]
 def dec(f): pass
Repository: python/mypy

Issue:
Unused section warning with warn_unused_configs and cache
With mypy 0.641 or the latest git master, and a config file like:

```ini
[mypy]
warn_unused_configs = True
[mypy-bdb]
ignore_missing_imports = True
```

checking a file like

```python3
import bdb
```

suppresses the `error: No library stub file for standard library module 'bdb'` error as expected.

However, when running mypy a second time, I assume results are retrieved from its cache, and it shows:

```
Warning: unused section(s) in mypy.ini: [mypy-bdb]
```

which means I can only use `--warn-unused-configs` selectively (like after editing the config), as otherwise, I'd get a lot of bogus warnings in day-to-day usage.

This is probably somewhat similar to #2960, which is the same kind of issue for `--warn-unused-ignores`.


Discussion:
I see this on 0.700 as well. passing `--no-warn-unused-configs` does silence the error, but it seems strange, since my 
```
[mypy-boto3]
ignore_missing_imports = True
```

is definitely doing something.
I'm getting the same problem with 0.701 with these lines in `mypy.ini`:

```
[mypy-tests.*]
disallow_untyped_defs = False
```

They're definitely working, but I still get the `Warning: unused section(s) in mypy.ini: [mypy-tests.*]` error. This happens regardless of whether `.mypy_cache` is present.

Though, oddly enough, I'm doing this in two different projects but only getting this problem in one of them. I haven't had time to do further debugging.
Increasing priority since this seems to affect quite a few people. I think that I've seen this myself as well.
I can do this. Or we can mark it "easy first issue"?
I suspect that this might be a bit difficult for a first issue, at least without a few hints.

Resolving patch:
diff --git a/mypy/main.py b/mypy/main.py
--- a/mypy/main.py
+++ b/mypy/main.py
@@ -87,7 +87,7 @@ def flush_errors(new_messages: List[str], serious: bool) -> None:
         blockers = True
         if not e.use_stdout:
             serious = True
-    if options.warn_unused_configs and options.unused_configs:
+    if options.warn_unused_configs and options.unused_configs and not options.incremental:
         print("Warning: unused section(s) in %s: %s" %
               (options.config_file,
                ", ".join("[mypy-%s]" % glob for glob in options.per_module_options.keys()


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
@@ -1193,6 +1193,7 @@ s1.py:2: error: Incompatible return value type (got "int", expected "str")
 [file mypy.ini]
 [[mypy]
 warn_unused_configs = True
+incremental = False
 [[mypy-bar]
 [[mypy-foo]
 [[mypy-baz.*]
Repository: python/mypy

Issue:
New semantic analyzer: daemon crash when stripping member lvalue
We've crashes like this with the new semantic analyzer:

```
Traceback (most recent call last):
  File "mypy/dmypy_server.py", line 223, in serve
  File "mypy/dmypy_server.py", line 262, in run_command
  File "mypy/dmypy_server.py", line 326, in cmd_check
  File "mypy/dmypy_server.py", line 362, in check
  File "mypy/dmypy_server.py", line 421, in initialize_fine_grained
  File "mypy/server/update.py", line 241, in update
  File "mypy/server/update.py", line 307, in update_one
  File "mypy/server/update.py", line 386, in update_module
  File "mypy/server/update.py", line 835, in propagate_changes_using_dependencies
  File "mypy/server/update.py", line 953, in reprocess_nodes
  File "mypy/server/aststripnew.py", line 35, in strip_target_new
  File "mypy/nodes.py", line 643, in accept
  File "mypy/server/aststripnew.py", line 109, in visit_func_def__StatementVisitor_glue
  File "mypy/server/aststripnew.py", line 122, in visit_func_def
  File "mypy/traverser.py", line 52, in visit_func_def
  File "mypy/traverser.py", line 49, in visit_func
  File "mypy/nodes.py", line 966, in accept
  File "mypy/server/aststripnew.py", line 57, in visit_block__StatementVisitor_glue
  File "mypy/server/aststripnew.py", line 60, in visit_block
  File "mypy/traverser.py", line 37, in visit_block
  File "mypy/nodes.py", line 1024, in accept
  File "mypy/server/aststripnew.py", line 145, in visit_assignment_stmt__StatementVisitor_glue
  File "mypy/server/aststripnew.py", line 152, in visit_assignment_stmt
  File "mypy/server/aststripnew.py", line 201, in process_lvalue_in_method
KeyError: '_user_context'
```

I'm working on a small test case that reproduces the issue.


Discussion:

Resolving patch:
diff --git a/mypy/server/update.py b/mypy/server/update.py
--- a/mypy/server/update.py
+++ b/mypy/server/update.py
@@ -950,7 +950,8 @@ def key(node: FineGrainedDeferredNode) -> int:
         if not manager.options.new_semantic_analyzer:
             strip_target(deferred.node)
         else:
-            patches = strip_target_new(deferred.node)
+            new_patches = strip_target_new(deferred.node)
+            patches.extend(new_patches)
     if not options.new_semantic_analyzer:
         re_analyze_nodes(file_node, nodes, manager, options)
     else:


Test patch:
diff --git a/test-data/unit/fine-grained.test b/test-data/unit/fine-grained.test
--- a/test-data/unit/fine-grained.test
+++ b/test-data/unit/fine-grained.test
@@ -8815,3 +8815,33 @@ B().x
 [out]
 ==
 ==
+
+[case testNewSemanticAnalyzerUpdateMethodAndClass]
+# flags: --new-semantic-analyzer
+import m
+
+m.x
+
+class A:
+    def f(self) -> None:
+        self.x = 0
+        m.y
+
+    def g(self) -> None:
+        m.x
+
+[file m.py]
+x = 0
+y = 0
+
+[file m.py.2]
+x = ''
+y = 0
+
+[file m.py.3]
+x = ''
+y = ''
+
+[out]
+==
+==
Repository: python/mypy

Issue:
Whole file `# type: ignore` does not silence import errors 
I just discovered PR #6830 and tried it out in master. It seems to work for the most part, but Mypy still complains about missing stub files. For example:

```
# type: ignore
import boto3 # This does not get ignored.
n:List[int] = 'a' # This gets ignored.
```

```
x.py:2: error: No library stub file for module 'boto3'
x.py:2: note: (Stub files are from https://github.com/python/typeshed)
```

It seems missing a critical stub file is a good use case for ignoring an entire file, but perhaps I'm missing something. Hope this helps!

version: mypy 0.710+dev.7cef06bc65d416ed3a533bbc4c630bd9417adb06.dirty




Discussion:
I can reproduce this. It looks like the `MypyFile.imports` aren't being marked as unreachable.

I'll take a peek at this when I have the time. Thanks for the heads-up!

Resolving patch:
diff --git a/mypy/fastparse.py b/mypy/fastparse.py
--- a/mypy/fastparse.py
+++ b/mypy/fastparse.py
@@ -38,6 +38,7 @@
 from mypy import message_registry
 from mypy.errors import Errors
 from mypy.options import Options
+from mypy.reachability import mark_block_unreachable
 
 try:
     # pull this into a final variable to make mypyc be quiet about the
@@ -309,7 +310,7 @@ def translate_stmt_list(self,
                 and min(self.type_ignores) < self.get_lineno(stmts[0])):
             self.errors.used_ignored_lines[self.errors.file].add(min(self.type_ignores))
             block = Block(self.fix_function_overloads(self.translate_stmt_list(stmts)))
-            block.is_unreachable = True
+            mark_block_unreachable(block)
             return [block]
 
         res = []  # type: List[Statement]
diff --git a/mypy/fastparse2.py b/mypy/fastparse2.py
--- a/mypy/fastparse2.py
+++ b/mypy/fastparse2.py
@@ -47,6 +47,7 @@
 from mypy.errors import Errors
 from mypy.fastparse import TypeConverter, parse_type_comment, bytes_to_human_readable_repr
 from mypy.options import Options
+from mypy.reachability import mark_block_unreachable
 
 try:
     from typed_ast import ast27
@@ -207,7 +208,7 @@ def translate_stmt_list(self,
                 and min(self.type_ignores) < self.get_lineno(stmts[0])):
             self.errors.used_ignored_lines[self.errors.file].add(min(self.type_ignores))
             block = Block(self.fix_function_overloads(self.translate_stmt_list(stmts)))
-            block.is_unreachable = True
+            mark_block_unreachable(block)
             return [block]
 
         res = []  # type: List[Statement]


Test patch:
diff --git a/test-data/unit/check-ignore.test b/test-data/unit/check-ignore.test
--- a/test-data/unit/check-ignore.test
+++ b/test-data/unit/check-ignore.test
@@ -242,6 +242,10 @@ IGNORE
 def f(): ...
 IGNORE
 
+[case testIgnoreWholeModule5]
+# type: ignore
+import MISSING
+
 [case testDontIgnoreWholeModule1]
 if True:
     # type: ignore
Repository: python/mypy

Issue:
New semantic analyzer: plugin generated methods are confused with user defined ones
This test case fails with new analyzer (note deferral):
```
[case testDataclassOrdering]
# flags: --python-version 3.6
from dataclasses import dataclass

defer: Yes

@dataclass(order=True)
class Application:
  name: str
  rating: int

class Yes: ...
[builtins fixtures/list.pyi]
```
with a bunch of errors
```
main:7: error: You may not have a custom __lt__ method when order=True
main:7: error: You may not have a custom __gt__ method when order=True
main:7: error: You may not have a custom __le__ method when order=True
main:7: error: You may not have a custom __ge__ method when order=True
```

Setting priority to high because it is a flaw in basic plugin functionality.


Discussion:

Resolving patch:
diff --git a/mypy/plugins/dataclasses.py b/mypy/plugins/dataclasses.py
--- a/mypy/plugins/dataclasses.py
+++ b/mypy/plugins/dataclasses.py
@@ -149,7 +149,7 @@ def transform(self) -> None:
                 ]
 
                 existing_method = info.get(method_name)
-                if existing_method is not None:
+                if existing_method is not None and not existing_method.plugin_generated:
                     assert existing_method.node
                     ctx.api.fail(
                         'You may not have a custom %s method when order=True' % method_name,


Test patch:
diff --git a/test-data/unit/check-dataclasses.test b/test-data/unit/check-dataclasses.test
--- a/test-data/unit/check-dataclasses.test
+++ b/test-data/unit/check-dataclasses.test
@@ -624,3 +624,21 @@ class C:
     x: int = dataclasses.field(default=1)
     y: str = dataclasses.field(metadata={"doc": "foo"})  # E: Attributes without a default cannot follow attributes with one
 [builtins fixtures/dict.pyi]
+
+[case testDataclassOrderingDeferred]
+# flags: --python-version 3.6 --new-semantic-analyzer
+from dataclasses import dataclass
+
+defer: Yes
+
+@dataclass(order=True)
+class Application:
+  name: str
+  rating: int
+
+a = Application('', 0)
+b = Application('', 0)
+a < b
+
+class Yes: ...
+[builtins fixtures/list.pyi]
Repository: python/mypy

Issue:
[Regression] dmypy run broken on Windows with 0.710
This is a regression in 0.710
My environment:
Windows 10
mypy (from pypi) 0.710
Python 3.7.2

I finally got to testing the release on Windows and it seems that dmypy run is broken on Windows. This seems to be an issue with how mypyc is handling the dmypy directory.

A sample of the behavior:
```
$ dmypy run -- test.py --follow-imports=error
Timed out waiting for daemon to start.
```

The work-around for now is to install mypy without mypyc via `pip install mypy --no-binary mypy`.

Not satisfied with that, I decided to start removing binary extensions until things worked. I was able to further narrow things down to the offending file, which is (oddly) `dmypy/__main__.py`. I'm not at all sure why deleting the extension module corresponding to that file should fix things, but it does. The corresponding PR that introduced this change is #6851.

cc @msullivan 


Discussion:
Aha, so based on the PR:
>dmypy can be compiled. Unfortunately extension modules can't be run as scripts, so we move dmypy.py to dmypy/client.py and add an interpreted dmypy/__main__.py

It seems that `dmypy/__main__.py` isn't meant to be compiled in the first place. Perhaps this is an easy fix then.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -89,7 +89,7 @@ def run(self):
         # Need to be runnable as scripts
         '__main__.py',
         'sitepkgs.py',
-        'dmypy/__main__.py',
+        os.path.join('dmypy', '__main__.py'),
 
         # Needs to be interpreted to provide a hook to interpreted plugins
         'interpreted_plugin.py',


Test patch:
Repository: python/mypy

Issue:
Using TypedDict in stub files with new analyzer produces error
mypy version: 0.710
Python version: 3.7.7

Given the following stub file (test.pyi):

```python
from typing_extensions import TypedDict

class StuffDict(TypedDict):
    foo: str
    bar: int

def thing(stuff: StuffDict) -> int: ...
```

Running `mypy --new-semantic-analyzer test.pyi` produces the following output:

```
test.pyi: error: Class test.StuffDict has abstract attributes "__getitem__", "__iter__", "__len__"
test.pyi: note: If it is meant to be abstract, add 'abc.ABCMeta' as an explicit metaclass
```


Discussion:
Thanks for reporting! This looks like something important to investigate.

Resolving patch:
diff --git a/mypy/newsemanal/semanal_classprop.py b/mypy/newsemanal/semanal_classprop.py
--- a/mypy/newsemanal/semanal_classprop.py
+++ b/mypy/newsemanal/semanal_classprop.py
@@ -51,6 +51,8 @@ def calculate_class_abstract_status(typ: TypeInfo, is_stub_file: bool, errors: E
     abstract attribute.  Also compute a list of abstract attributes.
     Report error is required ABCMeta metaclass is missing.
     """
+    if typ.typeddict_type:
+        return  # TypedDict can't be abstract
     concrete = set()  # type: Set[str]
     abstract = []  # type: List[str]
     abstract_in_this_class = []  # type: List[str]


Test patch:
diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test
--- a/test-data/unit/pythoneval.test
+++ b/test-data/unit/pythoneval.test
@@ -1367,3 +1367,19 @@ x: Dict[str, List[int]]
 reveal_type(x['test'][0])
 [out]
 _testNewAnalyzerBasicTypeshed_newsemanal.py:4: note: Revealed type is 'builtins.int*'
+
+[case testNewAnalyzerTypedDictInStub_newsemanal]
+import stub
+reveal_type(stub.thing)
+
+[file stub.pyi]
+from typing_extensions import TypedDict
+
+class StuffDict(TypedDict):
+    foo: str
+    bar: int
+
+def thing(stuff: StuffDict) -> int: ...
+
+[out]
+_testNewAnalyzerTypedDictInStub_newsemanal.py:2: note: Revealed type is 'def (stuff: TypedDict('stub.StuffDict', {'foo': builtins.str, 'bar': builtins.int})) -> builtins.int'
Repository: python/mypy

Issue:
New semantic analyser: Establish and document the defer() calling convention
(adding documentation label because it is also important for external plugin contributors)

The most important point is probably to decide on which side of `anal_type()` (and all other similar functions) we should call `defer()`. I think there are still some calls that are not needed (and may be even harmful during final iteration, note that the `defer()` calls in `typeanal.py` are correctly guarded for final iteration).

See also https://github.com/python/mypy/issues/6725


Discussion:

Resolving patch:
diff --git a/mypy/newsemanal/semanal.py b/mypy/newsemanal/semanal.py
--- a/mypy/newsemanal/semanal.py
+++ b/mypy/newsemanal/semanal.py
@@ -4262,10 +4262,14 @@ def defer(self, debug_context: Optional[Context] = None) -> None:
         """Defer current analysis target to be analyzed again.
 
         This must be called if something in the current target is
-        incomplete or has a placeholder node.
-
-        This must not be called during the final analysis iteration!
-        Instead, an error should be generated.
+        incomplete or has a placeholder node. However, this must *not*
+        be called during the final analysis iteration! Instead, an error
+        should be generated. Often 'process_placeholder' is a good
+        way to either defer or generate an error.
+
+        NOTE: Some methods, such as 'anal_type', 'mark_incomplete' and
+              'record_incomplete_ref', call this implicitly, or when needed.
+              They are usually preferable to a direct defer() call.
         """
         assert not self.final_iteration, 'Must not defer during final iteration'
         self.deferred = True


Test patch:
Repository: python/mypy

Issue:
Wrong inference of dataclasses with custom __init__ and varargs.
Small case to reproduce:

```python
from typing import Tuple
from dataclasses import dataclass

@dataclass
class Foo:
    spams: Tuple[int, ...]

    def __init__(self, *spams: int) -> None:
        self.spams = spams

def build_foo(*spams: int) -> Foo:
    return Foo(*spams)
```

Checking that program with mypy 0.670 (Python 3.6), results in:

```
bug.py:13: error: Argument 1 to "Foo" has incompatible type "*Tuple[int, ...]"; expected "Tuple[int, ...]"
```

Without the `@dataclass` decorator the program passes.  It seems that the dataclass is hiding the actual ` __init__`.



Discussion:
Hm, it looks like this behavior is unspecified. I just looked in the PEP, and it explicitly recommends using `@dataclass(init=False)` for custom `__init__` methods, see https://www.python.org/dev/peps/pep-0557/#custom-init-method. My works correctly with `init=False` (i.e. doesn't auto-generate the `__init__()`).

On the other hand, mypy probably should follow the runtime behavior for such case. This is however very low priority, since mypy works correctly in the documented case.
I think that the [python3.7 documentation](
https://docs.python.org/3/library/dataclasses.html#dataclasses.dataclass) defines the behavior:

```
init: If true (the default), a __init__() method will be generated.

If the class already defines __init__(), this parameter is ignored.
```

So if you have an `__init__`, then the dataclass is going to ignore the property that will instruct it to create an `__init__` method (at least, that's how I read it).

Resolving patch:
diff --git a/mypy/plugins/dataclasses.py b/mypy/plugins/dataclasses.py
--- a/mypy/plugins/dataclasses.py
+++ b/mypy/plugins/dataclasses.py
@@ -92,7 +92,11 @@ def transform(self) -> None:
             'frozen': _get_decorator_bool_argument(self._ctx, 'frozen', False),
         }
 
-        if decorator_arguments['init']:
+        # If there are no attributes, it may be that the new semantic analyzer has not
+        # processed them yet. In order to work around this, we can simply skip generating
+        # __init__ if there are no attributes, because if the user truly did not define any,
+        # then the object default __init__ with an empty signature will be present anyway.
+        if decorator_arguments['init'] and '__init__' not in info.names and attributes:
             add_method(
                 ctx,
                 '__init__',


Test patch:
diff --git a/test-data/unit/check-dataclasses.test b/test-data/unit/check-dataclasses.test
--- a/test-data/unit/check-dataclasses.test
+++ b/test-data/unit/check-dataclasses.test
@@ -16,6 +16,21 @@ Person('Jonh', 21, None)  # E: Too many arguments for "Person"
 
 [builtins fixtures/list.pyi]
 
+[case testDataclassesCustomInit]
+# flags: --python-version 3.6
+from dataclasses import dataclass
+
+@dataclass
+class A:
+    a: int
+
+    def __init__(self, a: str) -> None:
+        pass
+
+A('1')
+
+[builtins fixtures/list.pyi]
+
 [case testDataclassesBasicInheritance]
 # flags: --python-version 3.6
 from dataclasses import dataclass