Skip to content

Commit

Permalink
More docs
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 committed Aug 24, 2021
1 parent 585c4cc commit 3b77f3b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
2 changes: 0 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
## Editor integration

- [Visual Studio Code](./editors/vscode.md)
- [PyCharm](./editors/vscode.md)
- [MyPy](./editors/mypy.md)

## Guides

Expand Down
Binary file added docs/editors/pylance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 32 additions & 1 deletion docs/editors/vscode.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,35 @@ The first thing we need to do is to install
this is the extension that enables type checking and intellisense for Visual
Studio Code.

...
Once the extension is installed, we need to configure it to enable type
checking. To do so we need to change or add the following two settings:

```json
{
"python.languageServer": "Pylance",
"python.analysis.typeCheckingMode": "basic"
}
```

The first settings tells the editor to use Pylance as the language server. The
second setting tells the editor to enable type checking by using the basic type
checking mode. At the moment strict mode is not supported.

Once you have configured the settings, you can restart VS Code and you should be
getting type checking errors in vscode.

![Pylance showing a type error](./pylance.png)

## Notes

Unfortunately Pylance doesn't fully support `strawberry.field`, so for example
using this code will result in an error from Pylance:

```python
@strawberry.type
class User:
id: int
name: str = strawberry.field(resolver=a)
```

We will update Strawberry to support this when and if Pylance allows it.
9 changes: 4 additions & 5 deletions strawberry/object_type.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import dataclasses
from functools import partial
from typing import List, Optional, Type, cast

from .exceptions import MissingFieldAnnotationError, MissingReturnAnnotationError
from .field import StrawberryField
from .field import StrawberryField, field
from .types.type_resolver import _get_fields
from .types.types import FederationTypeParams, TypeDefinition
from .utils.str_converters import to_camel_case
Expand Down Expand Up @@ -123,7 +122,7 @@ def _process_type(
return cls


@__dataclass_transform__(order_default=True)
@__dataclass_transform__(order_default=True, field_descriptors=(field, StrawberryField))
def type(
cls: Type = None,
*,
Expand Down Expand Up @@ -160,7 +159,7 @@ def wrap(cls):
return wrap(cls)


@__dataclass_transform__(order_default=True)
@__dataclass_transform__(order_default=True, field_descriptors=(field, StrawberryField))
def input(
cls: Type = None,
*,
Expand All @@ -180,7 +179,7 @@ def input(
)


@__dataclass_transform__(order_default=True)
@__dataclass_transform__(order_default=True, field_descriptors=(field, StrawberryField))
def interface(
cls: Type = None,
*,
Expand Down
9 changes: 5 additions & 4 deletions strawberry/utils/typing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import Callable
import typing
from collections.abc import AsyncGenerator, Callable
from collections.abc import AsyncGenerator
from typing import Any, Tuple, Type, TypeVar, Union


Expand Down Expand Up @@ -102,6 +103,6 @@ def __dataclass_transform__(
eq_default: bool = True,
order_default: bool = False,
kw_only_default: bool = False,
field_descriptors: Tuple[Union[type, typing.Callable[..., Any]], ...] = (()),
) -> typing.Callable[[_T], _T]:
return lambda a: a
field_descriptors: Tuple[Union[type, Callable[..., Any]], ...] = (()),
) -> Callable[[_T], _T]:
return lambda a: a

0 comments on commit 3b77f3b

Please sign in to comment.