Repository: strawberry-graphql/strawberry

Issue:
Mypy 0.940 x Python 3.10 `scalar`overload
```
$ mypy strawberry/scalars.py
strawberry/scalars.py:9: error: No overload variant of "scalar" matches argument types "NewType", "str", "str", "Callable[[Any], Any]", "Callable[[Any], Any]"  [call-overload]
strawberry/scalars.py:9: note: Possible overload variants:
strawberry/scalars.py:9: note:     def scalar(*, name: Optional[str] = ..., description: Optional[str] = ..., specified_by_url: Optional[str] = ..., serialize: Callable[..., Any] = ..., parse_value: Optional[Callable[..., Any]] = ..., parse_literal: Optional[Callable[..., Any]] = ...) -> Callable[[_T], _T]
strawberry/scalars.py:9: note:     def [_T <: type] scalar(cls: _T, *, name: Optional[str] = ..., description: Optional[str] = ..., specified_by_url: Optional[str] = ..., serialize: Callable[..., Any] = ..., parse_value: Optional[Callable[..., Any]] = ..., parse_literal: Optional[Callable[..., Any]] = ...) -> _T
strawberry/scalars.py:23: error: No overload variant of "scalar" matches argument types "NewType", "str", "str", "Callable[[Any], str]", "Callable[[Any], bytes]"  [call-overload]
strawberry/scalars.py:23: note: Possible overload variants:
strawberry/scalars.py:23: note:     def scalar(*, name: Optional[str] = ..., description: Optional[str] = ..., specified_by_url: Optional[str] = ..., serialize: Callable[..., Any] = ..., parse_value: Optional[Callable[..., Any]] = ..., parse_literal: Optional[Callable[..., Any]] = ...) -> Callable[[_T], _T]
strawberry/scalars.py:23: note:     def [_T <: type] scalar(cls: _T, *, name: Optional[str] = ..., description: Optional[str] = ..., specified_by_url: Optional[str] = ..., serialize: Callable[..., Any] = ..., parse_value: Optional[Callable[..., Any]] = ..., parse_literal: Optional[Callable[..., Any]] = ...) -> _T
strawberry/scalars.py:31: error: No overload variant of "scalar" matches argument types "NewType", "str", "str", "Callable[[Any], str]", "Callable[[Any], bytes]"  [call-overload]
strawberry/scalars.py:31: note: Possible overload variants:
strawberry/scalars.py:31: note:     def scalar(*, name: Optional[str] = ..., description: Optional[str] = ..., specified_by_url: Optional[str] = ..., serialize: Callable[..., Any] = ..., parse_value: Optional[Callable[..., Any]] = ..., parse_literal: Optional[Callable[..., Any]] = ...) -> Callable[[_T], _T]
strawberry/scalars.py:31: note:     def [_T <: type] scalar(cls: _T, *, name: Optional[str] = ..., description: Optional[str] = ..., specified_by_url: Optional[str] = ..., serialize: Callable[..., Any] = ..., parse_value: Optional[Callable[..., Any]] = ..., parse_literal: Optional[Callable[..., Any]] = ...) -> _T
strawberry/scalars.py:41: error: No overload variant of "scalar" matches argument types "NewType", "str", "str", "Callable[[Any], str]", "Callable[[Any], bytes]"  [call-overload]
strawberry/scalars.py:41: note: Possible overload variants:
strawberry/scalars.py:41: note:     def scalar(*, name: Optional[str] = ..., description: Optional[str] = ..., specified_by_url: Optional[str] = ..., serialize: Callable[..., Any] = ..., parse_value: Optional[Callable[..., Any]] = ..., parse_literal: Optional[Callable[..., Any]] = ...) -> Callable[[_T], _T]
strawberry/scalars.py:41: note:     def [_T <: type] scalar(cls: _T, *, name: Optional[str] = ..., description: Optional[str] = ..., specified_by_url: Optional[str] = ..., serialize: Callable[..., Any] = ..., parse_value: Optional[Callable[..., Any]] = ..., parse_literal: Optional[Callable[..., Any]] = ...) -> _T
Found 4 errors in 1 file (checked 1 source file)
```


In 3.10, `NewType` is a [class rather than a function](https://docs.python.org/3/library/typing.html#newtype), I guess that's what is different with <= 3.9.


Discussion:

Resolving patch:
diff --git a/strawberry/custom_scalar.py b/strawberry/custom_scalar.py
--- a/strawberry/custom_scalar.py
+++ b/strawberry/custom_scalar.py
@@ -1,5 +1,16 @@
+import sys
 from dataclasses import dataclass
-from typing import Any, Callable, Mapping, Optional, Type, TypeVar, Union, overload
+from typing import (
+    Any,
+    Callable,
+    Mapping,
+    NewType,
+    Optional,
+    Type,
+    TypeVar,
+    Union,
+    overload,
+)
 
 from graphql import GraphQLScalarType
 
@@ -8,7 +19,11 @@
 from .utils.str_converters import to_camel_case
 
 
-_T = TypeVar("_T", bound=type)
+# in python 3.10+ NewType is a class
+if sys.version_info >= (3, 10):
+    _T = TypeVar("_T", bound=Union[type, NewType])
+else:
+    _T = TypeVar("_T", bound=type)
 
 
 def identity(x):


Test patch: