We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Mypy not treating bytes as typing.ByteString
According to the [docs](https://docs.python.org/3/library/typing.html#typing.ByteString), an argument typed as `bytes` should also accept `bytearray` and `memoryview`, but this doesn't seem to be the case.

The following example demonstrates this:

```python
def process(b: bytes) -> None:
    pass

process(memoryview(b"foo"))
```

Mypy produces the following error:

```
error: Argument 1 to "process" has incompatible type "memoryview"; expected "bytes"
```

I found https://github.com/python/mypy/issues/4871 which is essentially the same issue. If there hasn't been any relevant changes since April 2008, perhaps its a docs issue only?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mypy/semanal_classprop.py`
Content:
```
1 """Calculate some properties of classes.
2 
3 These happen after semantic analysis and before type checking.
4 """
5 
6 from typing import List, Set, Optional
7 from typing_extensions import Final
8 
9 from mypy.nodes import (
10     Node, TypeInfo, Var, Decorator, OverloadedFuncDef, SymbolTable, CallExpr, PromoteExpr,
11 )
12 from mypy.types import Instance, Type
13 from mypy.errors import Errors
14 from mypy.options import Options
15 
16 # Hard coded type promotions (shared between all Python versions).
17 # These add extra ad-hoc edges to the subtyping relation. For example,
18 # int is considered a subtype of float, even though there is no
19 # subclass relationship.
20 TYPE_PROMOTIONS = {
21     'builtins.int': 'float',
22     'builtins.float': 'complex',
23 }  # type: Final
24 
25 # Hard coded type promotions for Python 3.
26 #
27 # Note that the bytearray -> bytes promotion is a little unsafe
28 # as some functions only accept bytes objects. Here convenience
29 # trumps safety.
30 TYPE_PROMOTIONS_PYTHON3 = TYPE_PROMOTIONS.copy()  # type: Final
31 TYPE_PROMOTIONS_PYTHON3.update({
32     'builtins.bytearray': 'bytes',
33 })
34 
35 # Hard coded type promotions for Python 2.
36 #
37 # These promotions are unsafe, but we are doing them anyway
38 # for convenience and also for Python 3 compatibility
39 # (bytearray -> str).
40 TYPE_PROMOTIONS_PYTHON2 = TYPE_PROMOTIONS.copy()  # type: Final
41 TYPE_PROMOTIONS_PYTHON2.update({
42     'builtins.str': 'unicode',
43     'builtins.bytearray': 'str',
44 })
45 
46 
47 def calculate_class_abstract_status(typ: TypeInfo, is_stub_file: bool, errors: Errors) -> None:
48     """Calculate abstract status of a class.
49 
50     Set is_abstract of the type to True if the type has an unimplemented
51     abstract attribute.  Also compute a list of abstract attributes.
52     Report error is required ABCMeta metaclass is missing.
53     """
54     if typ.typeddict_type:
55         return  # TypedDict can't be abstract
56     concrete = set()  # type: Set[str]
57     abstract = []  # type: List[str]
58     abstract_in_this_class = []  # type: List[str]
59     if typ.is_newtype:
60         # Special case: NewTypes are considered as always non-abstract, so they can be used as:
61         #     Config = NewType('Config', Mapping[str, str])
62         #     default = Config({'cannot': 'modify'})  # OK
63         typ.abstract_attributes = []
64         return
65     for base in typ.mro:
66         for name, symnode in base.names.items():
67             node = symnode.node
68             if isinstance(node, OverloadedFuncDef):
69                 # Unwrap an overloaded function definition. We can just
70                 # check arbitrarily the first overload item. If the
71                 # different items have a different abstract status, there
72                 # should be an error reported elsewhere.
73                 if node.items:  # can be empty for invalid overloads
74                     func = node.items[0]  # type: Optional[Node]
75                 else:
76                     func = None
77             else:
78                 func = node
79             if isinstance(func, Decorator):
80                 fdef = func.func
81                 if fdef.is_abstract and name not in concrete:
82                     typ.is_abstract = True
83                     abstract.append(name)
84                     if base is typ:
85                         abstract_in_this_class.append(name)
86             elif isinstance(node, Var):
87                 if node.is_abstract_var and name not in concrete:
88                     typ.is_abstract = True
89                     abstract.append(name)
90                     if base is typ:
91                         abstract_in_this_class.append(name)
92             concrete.add(name)
93     # In stubs, abstract classes need to be explicitly marked because it is too
94     # easy to accidentally leave a concrete class abstract by forgetting to
95     # implement some methods.
96     typ.abstract_attributes = sorted(abstract)
97     if is_stub_file:
98         if typ.declared_metaclass and typ.declared_metaclass.type.fullname() == 'abc.ABCMeta':
99             return
100         if typ.is_protocol:
101             return
102         if abstract and not abstract_in_this_class:
103             def report(message: str, severity: str) -> None:
104                 errors.report(typ.line, typ.column, message, severity=severity)
105 
106             attrs = ", ".join('"{}"'.format(attr) for attr in sorted(abstract))
107             report("Class {} has abstract attributes {}".format(typ.fullname(), attrs), 'error')
108             report("If it is meant to be abstract, add 'abc.ABCMeta' as an explicit metaclass",
109                    'note')
110 
111 
112 def check_protocol_status(info: TypeInfo, errors: Errors) -> None:
113     """Check that all classes in MRO of a protocol are protocols"""
114     if info.is_protocol:
115         for type in info.bases:
116             if not type.type.is_protocol and type.type.fullname() != 'builtins.object':
117                 def report(message: str, severity: str) -> None:
118                     errors.report(info.line, info.column, message, severity=severity)
119                 report('All bases of a protocol must be protocols', 'error')
120 
121 
122 def calculate_class_vars(info: TypeInfo) -> None:
123     """Try to infer additional class variables.
124 
125     Subclass attribute assignments with no type annotation are assumed
126     to be classvar if overriding a declared classvar from the base
127     class.
128 
129     This must happen after the main semantic analysis pass, since
130     this depends on base class bodies having been fully analyzed.
131     """
132     for name, sym in info.names.items():
133         node = sym.node
134         if isinstance(node, Var) and node.info and node.is_inferred and not node.is_classvar:
135             for base in info.mro[1:]:
136                 member = base.names.get(name)
137                 if (member is not None
138                         and isinstance(member.node, Var)
139                         and member.node.is_classvar):
140                     node.is_classvar = True
141 
142 
143 def add_type_promotion(info: TypeInfo, module_names: SymbolTable, options: Options) -> None:
144     """Setup extra, ad-hoc subtyping relationships between classes (promotion).
145 
146     This includes things like 'int' being compatible with 'float'.
147     """
148     defn = info.defn
149     promote_target = None  # type: Optional[Type]
150     for decorator in defn.decorators:
151         if isinstance(decorator, CallExpr):
152             analyzed = decorator.analyzed
153             if isinstance(analyzed, PromoteExpr):
154                 # _promote class decorator (undocumented feature).
155                 promote_target = analyzed.type
156     if not promote_target:
157         promotions = (TYPE_PROMOTIONS_PYTHON3 if options.python_version[0] >= 3
158                       else TYPE_PROMOTIONS_PYTHON2)
159         if defn.fullname in promotions:
160             target_sym = module_names.get(promotions[defn.fullname])
161             # With test stubs, the target may not exist.
162             if target_sym:
163                 target_info = target_sym.node
164                 assert isinstance(target_info, TypeInfo)
165                 promote_target = Instance(target_info, [])
166     defn.info._promote = promote_target
167
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mypy/semanal_classprop.py b/mypy/semanal_classprop.py
--- a/mypy/semanal_classprop.py
+++ b/mypy/semanal_classprop.py
@@ -30,6 +30,7 @@
 TYPE_PROMOTIONS_PYTHON3 = TYPE_PROMOTIONS.copy()  # type: Final
 TYPE_PROMOTIONS_PYTHON3.update({
     'builtins.bytearray': 'bytes',
+    'builtins.memoryview': 'bytes',
 })
 
 # Hard coded type promotions for Python 2.
@@ -41,6 +42,7 @@
 TYPE_PROMOTIONS_PYTHON2.update({
     'builtins.str': 'unicode',
     'builtins.bytearray': 'str',
+    'builtins.memoryview': 'str',
 })

{"golden_diff": "diff --git a/mypy/semanal_classprop.py b/mypy/semanal_classprop.py\n--- a/mypy/semanal_classprop.py\n+++ b/mypy/semanal_classprop.py\n@@ -30,6 +30,7 @@\n TYPE_PROMOTIONS_PYTHON3 = TYPE_PROMOTIONS.copy()  # type: Final\n TYPE_PROMOTIONS_PYTHON3.update({\n     'builtins.bytearray': 'bytes',\n+    'builtins.memoryview': 'bytes',\n })\n \n # Hard coded type promotions for Python 2.\n@@ -41,6 +42,7 @@\n TYPE_PROMOTIONS_PYTHON2.update({\n     'builtins.str': 'unicode',\n     'builtins.bytearray': 'str',\n+    'builtins.memoryview': 'str',\n })\n", "issue": "Mypy not treating bytes as typing.ByteString\nAccording to the [docs](https://docs.python.org/3/library/typing.html#typing.ByteString), an argument typed as `bytes` should also accept `bytearray` and `memoryview`, but this doesn't seem to be the case.\r\n\r\nThe following example demonstrates this:\r\n\r\n```python\r\ndef process(b: bytes) -> None:\r\n    pass\r\n\r\nprocess(memoryview(b\"foo\"))\r\n```\r\n\r\nMypy produces the following error:\r\n\r\n```\r\nerror: Argument 1 to \"process\" has incompatible type \"memoryview\"; expected \"bytes\"\r\n```\r\n\r\nI found https://github.com/python/mypy/issues/4871 which is essentially the same issue. If there hasn't been any relevant changes since April 2008, perhaps its a docs issue only?\n", "before_files": [{"content": "\"\"\"Calculate some properties of classes.\n\nThese happen after semantic analysis and before type checking.\n\"\"\"\n\nfrom typing import List, Set, Optional\nfrom typing_extensions import Final\n\nfrom mypy.nodes import (\n    Node, TypeInfo, Var, Decorator, OverloadedFuncDef, SymbolTable, CallExpr, PromoteExpr,\n)\nfrom mypy.types import Instance, Type\nfrom mypy.errors import Errors\nfrom mypy.options import Options\n\n# Hard coded type promotions (shared between all Python versions).\n# These add extra ad-hoc edges to the subtyping relation. For example,\n# int is considered a subtype of float, even though there is no\n# subclass relationship.\nTYPE_PROMOTIONS = {\n    'builtins.int': 'float',\n    'builtins.float': 'complex',\n}  # type: Final\n\n# Hard coded type promotions for Python 3.\n#\n# Note that the bytearray -> bytes promotion is a little unsafe\n# as some functions only accept bytes objects. Here convenience\n# trumps safety.\nTYPE_PROMOTIONS_PYTHON3 = TYPE_PROMOTIONS.copy()  # type: Final\nTYPE_PROMOTIONS_PYTHON3.update({\n    'builtins.bytearray': 'bytes',\n})\n\n# Hard coded type promotions for Python 2.\n#\n# These promotions are unsafe, but we are doing them anyway\n# for convenience and also for Python 3 compatibility\n# (bytearray -> str).\nTYPE_PROMOTIONS_PYTHON2 = TYPE_PROMOTIONS.copy()  # type: Final\nTYPE_PROMOTIONS_PYTHON2.update({\n    'builtins.str': 'unicode',\n    'builtins.bytearray': 'str',\n})\n\n\ndef calculate_class_abstract_status(typ: TypeInfo, is_stub_file: bool, errors: Errors) -> None:\n    \"\"\"Calculate abstract status of a class.\n\n    Set is_abstract of the type to True if the type has an unimplemented\n    abstract attribute.  Also compute a list of abstract attributes.\n    Report error is required ABCMeta metaclass is missing.\n    \"\"\"\n    if typ.typeddict_type:\n        return  # TypedDict can't be abstract\n    concrete = set()  # type: Set[str]\n    abstract = []  # type: List[str]\n    abstract_in_this_class = []  # type: List[str]\n    if typ.is_newtype:\n        # Special case: NewTypes are considered as always non-abstract, so they can be used as:\n        #     Config = NewType('Config', Mapping[str, str])\n        #     default = Config({'cannot': 'modify'})  # OK\n        typ.abstract_attributes = []\n        return\n    for base in typ.mro:\n        for name, symnode in base.names.items():\n            node = symnode.node\n            if isinstance(node, OverloadedFuncDef):\n                # Unwrap an overloaded function definition. We can just\n                # check arbitrarily the first overload item. If the\n                # different items have a different abstract status, there\n                # should be an error reported elsewhere.\n                if node.items:  # can be empty for invalid overloads\n                    func = node.items[0]  # type: Optional[Node]\n                else:\n                    func = None\n            else:\n                func = node\n            if isinstance(func, Decorator):\n                fdef = func.func\n                if fdef.is_abstract and name not in concrete:\n                    typ.is_abstract = True\n                    abstract.append(name)\n                    if base is typ:\n                        abstract_in_this_class.append(name)\n            elif isinstance(node, Var):\n                if node.is_abstract_var and name not in concrete:\n                    typ.is_abstract = True\n                    abstract.append(name)\n                    if base is typ:\n                        abstract_in_this_class.append(name)\n            concrete.add(name)\n    # In stubs, abstract classes need to be explicitly marked because it is too\n    # easy to accidentally leave a concrete class abstract by forgetting to\n    # implement some methods.\n    typ.abstract_attributes = sorted(abstract)\n    if is_stub_file:\n        if typ.declared_metaclass and typ.declared_metaclass.type.fullname() == 'abc.ABCMeta':\n            return\n        if typ.is_protocol:\n            return\n        if abstract and not abstract_in_this_class:\n            def report(message: str, severity: str) -> None:\n                errors.report(typ.line, typ.column, message, severity=severity)\n\n            attrs = \", \".join('\"{}\"'.format(attr) for attr in sorted(abstract))\n            report(\"Class {} has abstract attributes {}\".format(typ.fullname(), attrs), 'error')\n            report(\"If it is meant to be abstract, add 'abc.ABCMeta' as an explicit metaclass\",\n                   'note')\n\n\ndef check_protocol_status(info: TypeInfo, errors: Errors) -> None:\n    \"\"\"Check that all classes in MRO of a protocol are protocols\"\"\"\n    if info.is_protocol:\n        for type in info.bases:\n            if not type.type.is_protocol and type.type.fullname() != 'builtins.object':\n                def report(message: str, severity: str) -> None:\n                    errors.report(info.line, info.column, message, severity=severity)\n                report('All bases of a protocol must be protocols', 'error')\n\n\ndef calculate_class_vars(info: TypeInfo) -> None:\n    \"\"\"Try to infer additional class variables.\n\n    Subclass attribute assignments with no type annotation are assumed\n    to be classvar if overriding a declared classvar from the base\n    class.\n\n    This must happen after the main semantic analysis pass, since\n    this depends on base class bodies having been fully analyzed.\n    \"\"\"\n    for name, sym in info.names.items():\n        node = sym.node\n        if isinstance(node, Var) and node.info and node.is_inferred and not node.is_classvar:\n            for base in info.mro[1:]:\n                member = base.names.get(name)\n                if (member is not None\n                        and isinstance(member.node, Var)\n                        and member.node.is_classvar):\n                    node.is_classvar = True\n\n\ndef add_type_promotion(info: TypeInfo, module_names: SymbolTable, options: Options) -> None:\n    \"\"\"Setup extra, ad-hoc subtyping relationships between classes (promotion).\n\n    This includes things like 'int' being compatible with 'float'.\n    \"\"\"\n    defn = info.defn\n    promote_target = None  # type: Optional[Type]\n    for decorator in defn.decorators:\n        if isinstance(decorator, CallExpr):\n            analyzed = decorator.analyzed\n            if isinstance(analyzed, PromoteExpr):\n                # _promote class decorator (undocumented feature).\n                promote_target = analyzed.type\n    if not promote_target:\n        promotions = (TYPE_PROMOTIONS_PYTHON3 if options.python_version[0] >= 3\n                      else TYPE_PROMOTIONS_PYTHON2)\n        if defn.fullname in promotions:\n            target_sym = module_names.get(promotions[defn.fullname])\n            # With test stubs, the target may not exist.\n            if target_sym:\n                target_info = target_sym.node\n                assert isinstance(target_info, TypeInfo)\n                promote_target = Instance(target_info, [])\n    defn.info._promote = promote_target\n", "path": "mypy/semanal_classprop.py"}], "after_files": [{"content": "\"\"\"Calculate some properties of classes.\n\nThese happen after semantic analysis and before type checking.\n\"\"\"\n\nfrom typing import List, Set, Optional\nfrom typing_extensions import Final\n\nfrom mypy.nodes import (\n    Node, TypeInfo, Var, Decorator, OverloadedFuncDef, SymbolTable, CallExpr, PromoteExpr,\n)\nfrom mypy.types import Instance, Type\nfrom mypy.errors import Errors\nfrom mypy.options import Options\n\n# Hard coded type promotions (shared between all Python versions).\n# These add extra ad-hoc edges to the subtyping relation. For example,\n# int is considered a subtype of float, even though there is no\n# subclass relationship.\nTYPE_PROMOTIONS = {\n    'builtins.int': 'float',\n    'builtins.float': 'complex',\n}  # type: Final\n\n# Hard coded type promotions for Python 3.\n#\n# Note that the bytearray -> bytes promotion is a little unsafe\n# as some functions only accept bytes objects. Here convenience\n# trumps safety.\nTYPE_PROMOTIONS_PYTHON3 = TYPE_PROMOTIONS.copy()  # type: Final\nTYPE_PROMOTIONS_PYTHON3.update({\n    'builtins.bytearray': 'bytes',\n    'builtins.memoryview': 'bytes',\n})\n\n# Hard coded type promotions for Python 2.\n#\n# These promotions are unsafe, but we are doing them anyway\n# for convenience and also for Python 3 compatibility\n# (bytearray -> str).\nTYPE_PROMOTIONS_PYTHON2 = TYPE_PROMOTIONS.copy()  # type: Final\nTYPE_PROMOTIONS_PYTHON2.update({\n    'builtins.str': 'unicode',\n    'builtins.bytearray': 'str',\n    'builtins.memoryview': 'str',\n})\n\n\ndef calculate_class_abstract_status(typ: TypeInfo, is_stub_file: bool, errors: Errors) -> None:\n    \"\"\"Calculate abstract status of a class.\n\n    Set is_abstract of the type to True if the type has an unimplemented\n    abstract attribute.  Also compute a list of abstract attributes.\n    Report error is required ABCMeta metaclass is missing.\n    \"\"\"\n    if typ.typeddict_type:\n        return  # TypedDict can't be abstract\n    concrete = set()  # type: Set[str]\n    abstract = []  # type: List[str]\n    abstract_in_this_class = []  # type: List[str]\n    if typ.is_newtype:\n        # Special case: NewTypes are considered as always non-abstract, so they can be used as:\n        #     Config = NewType('Config', Mapping[str, str])\n        #     default = Config({'cannot': 'modify'})  # OK\n        typ.abstract_attributes = []\n        return\n    for base in typ.mro:\n        for name, symnode in base.names.items():\n            node = symnode.node\n            if isinstance(node, OverloadedFuncDef):\n                # Unwrap an overloaded function definition. We can just\n                # check arbitrarily the first overload item. If the\n                # different items have a different abstract status, there\n                # should be an error reported elsewhere.\n                if node.items:  # can be empty for invalid overloads\n                    func = node.items[0]  # type: Optional[Node]\n                else:\n                    func = None\n            else:\n                func = node\n            if isinstance(func, Decorator):\n                fdef = func.func\n                if fdef.is_abstract and name not in concrete:\n                    typ.is_abstract = True\n                    abstract.append(name)\n                    if base is typ:\n                        abstract_in_this_class.append(name)\n            elif isinstance(node, Var):\n                if node.is_abstract_var and name not in concrete:\n                    typ.is_abstract = True\n                    abstract.append(name)\n                    if base is typ:\n                        abstract_in_this_class.append(name)\n            concrete.add(name)\n    # In stubs, abstract classes need to be explicitly marked because it is too\n    # easy to accidentally leave a concrete class abstract by forgetting to\n    # implement some methods.\n    typ.abstract_attributes = sorted(abstract)\n    if is_stub_file:\n        if typ.declared_metaclass and typ.declared_metaclass.type.fullname() == 'abc.ABCMeta':\n            return\n        if typ.is_protocol:\n            return\n        if abstract and not abstract_in_this_class:\n            def report(message: str, severity: str) -> None:\n                errors.report(typ.line, typ.column, message, severity=severity)\n\n            attrs = \", \".join('\"{}\"'.format(attr) for attr in sorted(abstract))\n            report(\"Class {} has abstract attributes {}\".format(typ.fullname(), attrs), 'error')\n            report(\"If it is meant to be abstract, add 'abc.ABCMeta' as an explicit metaclass\",\n                   'note')\n\n\ndef check_protocol_status(info: TypeInfo, errors: Errors) -> None:\n    \"\"\"Check that all classes in MRO of a protocol are protocols\"\"\"\n    if info.is_protocol:\n        for type in info.bases:\n            if not type.type.is_protocol and type.type.fullname() != 'builtins.object':\n                def report(message: str, severity: str) -> None:\n                    errors.report(info.line, info.column, message, severity=severity)\n                report('All bases of a protocol must be protocols', 'error')\n\n\ndef calculate_class_vars(info: TypeInfo) -> None:\n    \"\"\"Try to infer additional class variables.\n\n    Subclass attribute assignments with no type annotation are assumed\n    to be classvar if overriding a declared classvar from the base\n    class.\n\n    This must happen after the main semantic analysis pass, since\n    this depends on base class bodies having been fully analyzed.\n    \"\"\"\n    for name, sym in info.names.items():\n        node = sym.node\n        if isinstance(node, Var) and node.info and node.is_inferred and not node.is_classvar:\n            for base in info.mro[1:]:\n                member = base.names.get(name)\n                if (member is not None\n                        and isinstance(member.node, Var)\n                        and member.node.is_classvar):\n                    node.is_classvar = True\n\n\ndef add_type_promotion(info: TypeInfo, module_names: SymbolTable, options: Options) -> None:\n    \"\"\"Setup extra, ad-hoc subtyping relationships between classes (promotion).\n\n    This includes things like 'int' being compatible with 'float'.\n    \"\"\"\n    defn = info.defn\n    promote_target = None  # type: Optional[Type]\n    for decorator in defn.decorators:\n        if isinstance(decorator, CallExpr):\n            analyzed = decorator.analyzed\n            if isinstance(analyzed, PromoteExpr):\n                # _promote class decorator (undocumented feature).\n                promote_target = analyzed.type\n    if not promote_target:\n        promotions = (TYPE_PROMOTIONS_PYTHON3 if options.python_version[0] >= 3\n                      else TYPE_PROMOTIONS_PYTHON2)\n        if defn.fullname in promotions:\n            target_sym = module_names.get(promotions[defn.fullname])\n            # With test stubs, the target may not exist.\n            if target_sym:\n                target_info = target_sym.node\n                assert isinstance(target_info, TypeInfo)\n                promote_target = Instance(target_info, [])\n    defn.info._promote = promote_target\n", "path": "mypy/semanal_classprop.py"}]}