internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: typeddjango/django-stubs

Issue:
mypy@0.780 is out
We need to test if everything works on this new version and update the dependency.


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -21,7 +21,7 @@ def find_stub_files(name: str) -> List[str]:
     readme = f.read()
 
 dependencies = [
-    'mypy>=0.770,<0.780',
+    'mypy>=0.780,<0.790',
     'typing-extensions',
     'django',
 ]


Test patch:
diff --git a/scripts/enabled_test_modules.py b/scripts/enabled_test_modules.py
--- a/scripts/enabled_test_modules.py
+++ b/scripts/enabled_test_modules.py
@@ -185,6 +185,8 @@
     ],
     'files': [
         'Incompatible types in assignment (expression has type "IOBase", variable has type "File")',
+        'Argument 1 to "TextIOWrapper" has incompatible type "File"; expected "BinaryIO"',
+        'Incompatible types in assignment (expression has type "BinaryIO", variable has type "File")',
     ],
     'filtered_relation': [
         'has no attribute "name"',
@@ -378,6 +380,7 @@
     'responses': [
         'Argument 1 to "TextIOWrapper" has incompatible type "HttpResponse"; expected "IO[bytes]"',
         '"FileLike" has no attribute "closed"',
+        'Argument 1 to "TextIOWrapper" has incompatible type "HttpResponse"; expected "BinaryIO"',
     ],
     'reverse_lookup': [
         "Cannot resolve keyword 'choice' into field"
diff --git a/scripts/tests_extension_hook.py b/scripts/tests_extension_hook.py
--- a/scripts/tests_extension_hook.py
+++ b/scripts/tests_extension_hook.py
@@ -1,5 +1,5 @@
-from pytest_mypy.collect import File
-from pytest_mypy.item import YamlTestItem
+from pytest_mypy_plugins.collect import File
+from pytest_mypy_plugins.item import YamlTestItem
 
 
 def django_plugin_hook(test_item: YamlTestItem) -> None:
Repository: typeddjango/django-stubs

Issue:
Bump max mypy version
I just updated `mypy` to `0.782` and got the following error:

> ERROR: django-stubs 1.5.0 has requirement mypy<0.780,>=0.770, but you'll have mypy 0.782 which is incompatible.

So far I have not encountered any issues despite this error (it still installed it regardless).

Can the max version requirement be safely increased?


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -21,7 +21,7 @@ def find_stub_files(name: str) -> List[str]:
     readme = f.read()
 
 dependencies = [
-    'mypy>=0.780,<0.790',
+    'mypy>=0.782,<0.790',
     'typing-extensions',
     'django',
 ]


Test patch:
Repository: typeddjango/django-stubs

Issue:
Field missing from django_stubs_ext.patch._need_generic
# Bug report

A custom `Field` subclass does not type-check properly, even when using django_stubs_ext.

## What's wrong

The `Field` class is not included in `django_stubs_ext.patch._need_generic`.

## How is that should be

If the `Field` class were included in `django_stubs_ext.patch._need_generic`, the following would type check properly instead of causing a crash:
```
class Foo(Field[int, int]):
    pass

class Bar(TextField[str, str]):
    pass
```

## System information

- OS: Debian
- `python` version: 3.8.6
- `django` version: 3.1.4
- `mypy` version: 0.790
- `django-stubs` version: 1.7.0
- `django-stubs-ext` version: 0.1.0



Discussion:

Resolving patch:
diff --git a/django_stubs_ext/django_stubs_ext/patch.py b/django_stubs_ext/django_stubs_ext/patch.py
--- a/django_stubs_ext/django_stubs_ext/patch.py
+++ b/django_stubs_ext/django_stubs_ext/patch.py
@@ -3,6 +3,7 @@
 from django import VERSION as VERSION
 from django.contrib.admin import ModelAdmin
 from django.contrib.admin.options import BaseModelAdmin
+from django.db.models.fields import Field
 from django.db.models.manager import BaseManager
 from django.db.models.query import QuerySet
 from django.views.generic.edit import FormMixin
@@ -38,6 +39,7 @@ def __repr__(self) -> str:
     MPGeneric(ModelAdmin),
     MPGeneric(FormMixin),
     MPGeneric(BaseModelAdmin),
+    MPGeneric(Field),
     # These types do have native `__class_getitem__` method since django 3.1:
     MPGeneric(QuerySet, (3, 1)),
     MPGeneric(BaseManager, (3, 1)),


Test patch:
Repository: typeddjango/django-stubs

Issue:
"field" and "exclude" arguments of model_to_dict() do not accept sets
# Bug report

## What's wrong

Our test suite contains code that simplifies to this fragment:
```py
from typing import Mapping

from django.db.models.base import Model
from django.forms import model_to_dict


def check(instance: Model, data: Mapping[str, object]) -> None:
    assert data == model_to_dict(instance, fields=data.keys())
```

When checking that with mypy, it reports:
```
testcase.py:8: error: Argument "fields" to "model_to_dict" has incompatible type "AbstractSet[str]";
expected "Union[List[Union[Callable[..., Any], str]], Sequence[str], Literal['__all__'], None]"
[arg-type]
        assert data == model_to_dict(instance, fields=data.keys())
```

## How is that should be

The implementation of `model_to_dict()` only needs `__bool__()` and `__contains__()` to be provided by the `fields` and `exclude` arguments, so passing a keys set should not be flagged as an error.

I think a solution could be to replace `Sequence` in the stubs annotation with `Collection`.

## System information

- OS: Ubuntu Linux 18.04
- `python` version: 3.6.9
- `django` version: 2.2.1
- `mypy` version: 0.812
- `django-stubs` version: 1.8.0



Discussion:
@mthuurne please, feel free to send a PR! 👍 

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -21,7 +21,7 @@ def find_stub_files(name: str) -> List[str]:
     readme = f.read()
 
 dependencies = [
-    "mypy>=0.790",
+    "mypy>=0.900",
     "typing-extensions",
     "django",
     "django-stubs-ext",


Test patch:
Repository: typeddjango/django-stubs

Issue:
Mypy version 0.940 released, causes tests to fail
On [11th March 2022, Mypy version 0.940](https://pypi.org/project/mypy/#history) was released, causing django-stubs tests run by pytest to fail in Github Actions started on or after 11th Match.
We either need to use version 0.931 of mypy for local testing and Github actions, or find a way around the error `Cannot determine type of "Any"` being thrown due to mypy version 0.940 on running the pytest command.


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -21,7 +21,7 @@ def find_stub_files(name: str) -> List[str]:
     readme = f.read()
 
 dependencies = [
-    "mypy>=0.931",
+    "mypy>=0.930,<0.940",
     "django",
     "django-stubs-ext>=0.3.0",
     "tomli",


Test patch:
Repository: typeddjango/django-stubs

Issue:
Support mypy 0.960
[mypy 0.960](https://github.com/python/mypy/releases/tag/v0.960) was released yesterday.

The latest release [v1.11.0 of `django-stubs`, which added support for mypy 0.950](https://github.com/typeddjango/django-stubs/releases/tag/v1.11.0), was also released yesterday, but it currently still [enforces a version less than 0.960](https://github.com/typeddjango/django-stubs/blob/master/setup.py#L23).

So it's not possible to use yesterday's `mypy` release with yesterday's `django-stubs` release at the moment.


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -20,7 +20,7 @@ def find_stub_files(name: str) -> List[str]:
     readme = f.read()
 
 dependencies = [
-    "mypy>=0.930,<0.960",
+    "mypy>=0.930,<0.970",
     "django",
     "django-stubs-ext>=0.4.0",
     "tomli",
@@ -32,7 +32,7 @@ def find_stub_files(name: str) -> List[str]:
 
 setup(
     name="django-stubs",
-    version="1.11.0",
+    version="1.11.1",
     description="Mypy stubs for Django",
     long_description=readme,
     long_description_content_type="text/markdown",


Test patch:
diff --git a/tests/typecheck/fields/test_base.yml b/tests/typecheck/fields/test_base.yml
--- a/tests/typecheck/fields/test_base.yml
+++ b/tests/typecheck/fields/test_base.yml
@@ -27,7 +27,7 @@
         booking = Booking()
         reveal_type(booking.id)  # N: Revealed type is "builtins.int"
         reveal_type(booking.time_range)  # N: Revealed type is "Any"
-        reveal_type(booking.some_decimal)  # N: Revealed type is "decimal.Decimal"
+        reveal_type(booking.some_decimal)  # N: Revealed type is "_decimal.Decimal"
     installed_apps:
         - myapp
     files:
Repository: typeddjango/django-stubs

Issue:
Any `RelatedManager`s does not exist on cached runs for model instances
## What's wrong

Accessing `RelatedManager`s through any `related_name=` values on model instances yields error seen below __on cached runs__

```
error: "Purchase" has no attribute "receipts"  [attr-defined]
    reveal_type(purchase.receipts)
```

Inspecting the `.mypy_cache` I can verify that there's no entry in `"names"` for such attributes. Making me highly suspect the plugin is setting `no_serialize=True` incorrectly for generated `RelatedManager`s.

## How is that should be

Cached runs should not error on attributes existing on non cached runs. i.e. Entry under `"names"` in cache should exist for attributes inheriting `RelatedManager`.

## System information

- OS:
- `python` version: 3.10
- `django` version: 4.1.1
- `mypy` version: 0.971
- `django-stubs` version: 1.12.0
- `django-stubs-ext` version: 0.5.0



Discussion:
Seems to be #825 that introduced the relevant `no_serialize=True` lines.

Resolving patch:
diff --git a/mypy_django_plugin/transformers/models.py b/mypy_django_plugin/transformers/models.py
--- a/mypy_django_plugin/transformers/models.py
+++ b/mypy_django_plugin/transformers/models.py
@@ -538,9 +538,7 @@ def run_with_model_cls(self, model_cls: Type[Model]) -> None:
                     model_info=related_model_info, derived_from="_default_manager"
                 )
                 if default_reverse_manager_info:
-                    self.add_new_node_to_model_class(
-                        attname, Instance(default_reverse_manager_info, []), no_serialize=True
-                    )
+                    self.add_new_node_to_model_class(attname, Instance(default_reverse_manager_info, []))
                     continue
 
                 # The reverse manager we're looking for doesn't exist. So we
@@ -562,7 +560,6 @@ def run_with_model_cls(self, model_cls: Type[Model]) -> None:
                     module=self.api.modules[related_model_info.module_name],
                     name=f"{related_model_cls.__name__}_RelatedManager",
                     bases=[parametrized_related_manager_type, default_manager_type],
-                    no_serialize=True,
                 )
                 new_related_manager_info.metadata["django"] = {"related_manager_to_model": related_model_info.fullname}
                 # Stash the new reverse manager type fullname on the related model, so we don't duplicate
@@ -572,7 +569,7 @@ def run_with_model_cls(self, model_cls: Type[Model]) -> None:
                     derived_from="_default_manager",
                     fullname=new_related_manager_info.fullname,
                 )
-                self.add_new_node_to_model_class(attname, Instance(new_related_manager_info, []), no_serialize=True)
+                self.add_new_node_to_model_class(attname, Instance(new_related_manager_info, []))
 
 
 class AddExtraFieldMethods(ModelClassInitializer):


Test patch:
Repository: typeddjango/django-stubs

Issue:
Next release planning (1.14.0)
Tracking a few regressions in [version 1.13.2](https://github.com/typeddjango/django-stubs/releases/tag/1.13.2), we should probably get out a release quickly once these are resolved.

* #1335
  * Fixes #1333
  * Fixes #1336
* https://github.com/typeddjango/django-stubs/pull/1331
  * Fixes #1330
* #1345
  * Fixes #1327

We can update to mypy 0.991 thanks to @flaeppe, and will call the next version 1.14.0.

* #1329
  * Unblocked #1260 
  * Fixes #1261

Also some nice to have PRs still waiting for community reviewers:
* #1309
* #1308
* #1315



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -36,7 +36,7 @@ def find_stub_files(name: str) -> List[str]:
 
 setup(
     name="django-stubs",
-    version="1.13.2",
+    version="1.14.0",
     description="Mypy stubs for Django",
     long_description=readme,
     long_description_content_type="text/markdown",


Test patch:
Repository: typeddjango/django-stubs

Issue:
Next release planning (1.15.0)
I'll make a new release a soonish, perhaps this weekend or next week, now that mypy 1.0 is being tested in CI and used for `django-stubs[compatible-mypy]`.

* #1360

I'd like to make a dual release together with djangorestframework-stubs, so recommended mypy version stays in sync between both projects. But there's some work to be done still on that side: https://github.com/typeddjango/djangorestframework-stubs/issues/324#issuecomment-1421098490

Additionally, nice to have PRs waiting, communtiy reviewers welcome:

* #1309
* #1308



Discussion:
Everything needed for the release has been merged. I'll be running a few more checks and then hopefully can make the releases.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -36,7 +36,7 @@ def find_stub_files(name: str) -> List[str]:
 
 setup(
     name="django-stubs",
-    version="1.14.0",
+    version="1.15.0",
     description="Mypy stubs for Django",
     long_description=readme,
     long_description_content_type="text/markdown",


Test patch:
Repository: typeddjango/django-stubs

Issue:
Next release planning (1.16.0; django-stubs-ext 0.8.0)
Will be making a release soon-ish (TM). If someone is waiting to get their PR reviewed, or a merged PR released, please mention here.



Discussion:
We'll probably want to update recommended & CI mypy to 1.1.1.

<details><summary>Collapsed error output from mypy 1.1.1</summary>
This needs fixing: https://github.com/typeddjango/django-stubs/actions/runs/4350182908/jobs/7600636354

```
django-stubs/utils/datastructures.pyi:68: error: Signature of "setdefault" incompatible with supertype "MutableMapping"
django-stubs/utils/datastructures.pyi:68: note:      Superclass:
django-stubs/utils/datastructures.pyi:68: note:          @overload
django-stubs/utils/datastructures.pyi:68: note:          def setdefault(self, _K, None = ..., /) -> Optional[_V]
django-stubs/utils/datastructures.pyi:68: note:          @overload
django-stubs/utils/datastructures.pyi:68: note:          def setdefault(self, _K, _V, /) -> _V
django-stubs/utils/datastructures.pyi:68: note:      Subclass:
django-stubs/utils/datastructures.pyi:68: note:          def setdefault(self, key: _K, default: _V = ...) -> _V
Found 1 error in 1 file (checked 675 source files)
```

</details>
Created PR to update mypy & fix new errors. django-stubs and djangorestframework-stubs:

* #1391
* https://github.com/typeddjango/djangorestframework-stubs/pull/374
It would also be great if we get a new release for `django-stubs-ext`

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ def find_stub_files(name: str) -> List[str]:
 dependencies = [
     "mypy>=0.980",
     "django",
-    "django-stubs-ext>=0.7.0",
+    "django-stubs-ext>=0.8.0",
     "tomli",
     # Types:
     "typing-extensions",
@@ -36,7 +36,7 @@ def find_stub_files(name: str) -> List[str]:
 
 setup(
     name="django-stubs",
-    version="1.15.0",
+    version="1.16.0",
     description="Mypy stubs for Django",
     long_description=readme,
     long_description_content_type="text/markdown",
@@ -44,8 +44,8 @@ def find_stub_files(name: str) -> List[str]:
     url="https://github.com/typeddjango/django-stubs",
     author="Maksim Kurnikov",
     author_email="maxim.kurnikov@gmail.com",
-    maintainer="Nikita Sobolev",
-    maintainer_email="mail@sobolevn.me",
+    maintainer="Marti Raudsepp",
+    maintainer_email="marti@juffo.org",
     py_modules=[],
     python_requires=">=3.7",
     install_requires=dependencies,


Test patch:
Repository: typeddjango/django-stubs

Issue:
Don't require `tomli` on Python 3.11
# Bug report

## What's wrong

Hi!

I'm in the process of upgrading my app to use Python 3.11 and noticed that the only library that requires `tomli` is `django-stubs`, as all other have it marked as an optional dependency required only if Python version is lower than 3.11.

<img width="878" alt="Screenshot 2023-03-20 at 16 57 32" src="https://user-images.githubusercontent.com/7062874/226398474-12acd3f7-446c-4c4f-9b3a-70675dd0093f.png">


## How is that should be

`django-stubs` should only install `tomli` on Python <3.11  and use `tomllib` on Python 3.11. As far as I understand their interfaces are compatible, which is why all the libraries listed above just use `tomllib` on Python 3.11 and `tomli` on older versions

Example from `black`:

https://github.com/psf/black/blob/ef6e079901d53a42dfae4ab10b081ce7a73a47b5/pyproject.toml#L71

https://github.com/psf/black/blob/ef6e079901d53a42dfae4ab10b081ce7a73a47b5/src/black/files.py#L26-L34

As far as I see, the replacement should be pretty straightforward and I'd be happy to provide a PR.

## System information

- OS: macOS 12.6.3
- `python` version: 3.11.2
- `django` version: 4.1.7
- `mypy` version: 1.0.1
- `django-stubs` version: 1.14.0
- `django-stubs-ext` version: 0.7.0



Discussion:
PR is welcome!

Resolving patch:
diff --git a/mypy_django_plugin/config.py b/mypy_django_plugin/config.py
--- a/mypy_django_plugin/config.py
+++ b/mypy_django_plugin/config.py
@@ -1,10 +1,14 @@
 import configparser
+import sys
 import textwrap
 from functools import partial
 from pathlib import Path
 from typing import Any, Callable, Dict, NoReturn, Optional
 
-import tomli
+if sys.version_info[:2] >= (3, 11):
+    import tomllib
+else:
+    import tomli as tomllib
 
 INI_USAGE = """
 (config)
@@ -64,8 +68,8 @@ def parse_toml_file(self, filepath: Path) -> None:
         toml_exit: Callable[[str], NoReturn] = partial(exit_with_error, is_toml=True)
         try:
             with filepath.open(mode="rb") as f:
-                data = tomli.load(f)
-        except (tomli.TOMLDecodeError, OSError):
+                data = tomllib.load(f)
+        except (tomllib.TOMLDecodeError, OSError):
             toml_exit(COULD_NOT_LOAD_FILE)
 
         try:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -23,7 +23,7 @@ def find_stub_files(name: str) -> List[str]:
     "mypy>=0.980",
     "django",
     "django-stubs-ext>=0.8.0",
-    "tomli",
+    "tomli; python_version < '3.11'",
     # Types:
     "typing-extensions",
     "types-pytz",


Test patch:
Repository: typeddjango/django-stubs

Issue:
django-stubs-ext version schema
# Bug report

## What's wrong

I want to automatically update to newer versions of libraries, and so I use a version specifier like `~=1.0` to upgrade to versions  `1.x.x`, hoping that dependencies follow semver. When the version starts with `0`, I need to use `~=0.1.0` to upgrade to all `0.1.x` versions because semver defines bumping the minor version (i.e. `0.2.0`) as a breaking change.

I think django-stubs follows this, at least in spirit, but django-stubs-ext only bumps the minor version: https://pypi.org/project/django-stubs-ext/#history

## How is that should be

I would love for django-stubs-ext to either:

- Bump the patch release for mostly-backward-compatible changes (similar to how django-stubs bumps the minor version), or
- My preference: bump the major version to `1` to match django-stubs and continue bumping the minor version the way we have been

## System information

N/A


Discussion:
I think there's no particular reason why we're still using `0.x` versions for django-stubs-ext? @sobolevn?

We should release django-stubs-ext `1.0.0` next time around.

I think we can release the same version as django has.

Basically like `django-major.django-minor.our-own-patch`
And we can only claim to support this version. Other versions can be "partially supported".
Oh, right, we already had this discussion at https://github.com/typeddjango/django-stubs/issues/1095#issuecomment-1307066177.


Resolving patch:
diff --git a/django_stubs_ext/setup.py b/django_stubs_ext/setup.py
--- a/django_stubs_ext/setup.py
+++ b/django_stubs_ext/setup.py
@@ -10,9 +10,11 @@
     "typing-extensions",
 ]
 
+# NB! For clarity, keep version major.minor.patch in sync with django-stubs.
+# It's fine to skip django-stubs-ext releases, but when doing a release, update this to newest django-stubs version.
 setup(
     name="django-stubs-ext",
-    version="0.8.0",
+    version="4.2.0",
     description="Monkey-patching and extensions for django-stubs",
     long_description=readme,
     long_description_content_type="text/markdown",
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ def find_stub_files(name: str) -> List[str]:
 dependencies = [
     "mypy>=0.980",
     "django",
-    "django-stubs-ext>=0.8.0",
+    "django-stubs-ext>=4.2.0",
     "tomli; python_version < '3.11'",
     # Types:
     "typing-extensions",
@@ -36,7 +36,7 @@ def find_stub_files(name: str) -> List[str]:
 
 setup(
     name="django-stubs",
-    version="1.16.0",
+    version="4.2.0",
     description="Mypy stubs for Django",
     long_description=readme,
     long_description_content_type="text/markdown",


Test patch:
Repository: typeddjango/django-stubs

Issue:
Next release planning (4.2.1)
* There's already plenty of merged good stuff in master, including mypy 1.3.0 for compatible-mypy.
* As mentioned in last release notes, Python 3.7 support and Django 4.0 support has been dropped.
* The `TypedModelMeta` feature is now fixed (it was deferred from last release, https://github.com/typeddjango/django-stubs/issues/1450#issuecomment-1525663652)

Please comment here if you want to push something else for this release.



Discussion:

Resolving patch:
diff --git a/django_stubs_ext/setup.py b/django_stubs_ext/setup.py
--- a/django_stubs_ext/setup.py
+++ b/django_stubs_ext/setup.py
@@ -15,7 +15,7 @@
 # It's fine to skip django-stubs-ext releases, but when doing a release, update this to newest django-stubs version.
 setup(
     name="django-stubs-ext",
-    version="4.2.0",
+    version="4.2.1",
     description="Monkey-patching and extensions for django-stubs",
     long_description=readme,
     long_description_content_type="text/markdown",
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -23,7 +23,7 @@ def find_stub_files(name: str) -> List[str]:
 dependencies = [
     "mypy>=1.0.0",
     "django",
-    "django-stubs-ext>=4.2.0",
+    "django-stubs-ext>=4.2.1",
     "tomli; python_version < '3.11'",
     # Types:
     "typing-extensions",
@@ -37,7 +37,7 @@ def find_stub_files(name: str) -> List[str]:
 
 setup(
     name="django-stubs",
-    version="4.2.0",
+    version="4.2.1",
     description="Mypy stubs for Django",
     long_description=readme,
     long_description_content_type="text/markdown",


Test patch: