Skip to content

Commit cde8668

Browse files
committed
wordsmith
1 parent 0e4c46f commit cde8668

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

docs/types.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,27 @@ SomeClass(a_number=42)
3535

3636
Even when going all-in on type annotations, you will need {func}`attrs.field` for some advanced features, though.
3737

38-
One of those features are decorator-based features like defaults.
39-
It's important to remember that *attrs* doesn't do any magic behind your back here:
40-
The decorators are implemented using an object that is returned by the call to {func}`attrs.field`.
41-
42-
Attributes that only carry a class annotation do not have that object so trying to call a method on it will inevitably fail.
38+
One of those features is decorator-based functionality like defaults.
39+
It's important to remember that *attrs* does not perform any hidden magic here:
40+
The decorators are implemented using the object returned by the call to {func}`attrs.field`.
41+
Attributes that only carry a class annotation do not have that object, so trying to call a method on it will inevitably fail.
4342

4443

4544
## Forward references
4645

4746
Python doesn't allow referencing classes in type annotations that haven't been defined yet.
48-
Since it's a common requirement in real-world code, though, there's been traditionally the workaround of defining them using string literals:
47+
Since this is a common requirement in real-world code, the traditional workaround has been defining them using string literals:
4948

5049
```python
5150
class C:
5251
another_c: "C"
5352
```
5453

55-
This is called a *forward references* ({pep}`526`) and can be enabled automatically for a whole file by using `from __future__ import annotations` ({pep}`563`).
54+
These are called *forward references* ({pep}`526`) and can be enabled automatically for a whole file by using `from __future__ import annotations` ({pep}`563`).
5655

57-
As of Python 3.14 this is not necessary anymore since it introduced [*deferred evaluation of annotations*](https://docs.python.org/3/whatsnew/3.14.html#whatsnew314-deferred-annotations) ({pep}`649` and {pep}`749`) that has a more sophisticated system based on {class}`annotationlib.ForwardRef`s but serves to solve the same problem.
56+
As of Python 3.14, this is no longer necessary because it introduced [*deferred evaluation of annotations*](https://docs.python.org/3/whatsnew/3.14.html#whatsnew314-deferred-annotations) ({pep}`649` and {pep}`749`) that has a more sophisticated system based on {class}`annotationlib.ForwardRef`s, but ultimately solves the same problem.
5857

59-
In both cases, if you need to resolve these to real types, you can call {func}`attrs.resolve_types` which will update the attributes in place.
58+
In both cases, if you need to resolve these to real types, you can call {func}`attrs.resolve_types`, which will update the attributes in place.
6059

6160

6261
## Class variables and constants
@@ -102,13 +101,13 @@ class SomeClass:
102101
list_of_numbers = attr.ib(factory=list, type=list[int])
103102
```
104103

105-
The approach used for `list_of_numbers` one is only available in our [old-style API](names.md) which is why the example still uses it.
104+
The approach used for `list_of_numbers` is only available in our [old-style API](names.md) which is why the example still uses it.
106105

107106

108107
### Pyright / VS Code
109108

110109
*attrs* integrates with Microsoft's [Pyright] via {pep}`681`.
111-
While Pyright's not as commonly used as a type-checker, it's widely used as the foundation of [VS Code](https://code.visualstudio.com/)'s proprietary [Pylance](https://github.com/microsoft/pylance-release) language server that powers [its Python support](https://marketplace.visualstudio.com/items?itemName=ms-python.python).
110+
While Pyright is not as commonly used as a standalone type checker, it's widely used as the foundation of [VS Code](https://code.visualstudio.com/)'s proprietary [Pylance](https://github.com/microsoft/pylance-release) language server that powers [its Python support](https://marketplace.visualstudio.com/items?itemName=ms-python.python).
112111

113112
Pyright has grown several *attrs*-specific features over the years, but its inferred types are still a tiny subset of those supported by Mypy, including:
114113

@@ -121,7 +120,7 @@ Your constructive feedback is welcome in both [attrs#795](https://github.com/pyt
121120
Keep in mind that the decision on improving *attrs* support in Pyright is entirely Microsoft's prerogative and they unequivocally indicated that they'll only add support for features that go through the PEP process.
122121
We as the *attrs* project unfortunately have no influence over that.
123122

124-
Note that there's a community fork called [*basedpyright*](https://docs.basedpyright.com/) that implements some of Microsoft's closed-source Pylance features, so they're available in other editors like [Zed](https://zed.dev) or other VS Code forks that are not allowed to use Pylance.
123+
Note that there's a community fork called [*basedpyright*](https://docs.basedpyright.com/) that implements some of Microsoft's closed-source Pylance features, so they're available in other editors like [Zed](https://zed.dev) and VS Code forks that are not allowed to use Pylance.
125124
Unfortunately, better *attrs* support doesn't appear to be part of their goals.
126125

127126

@@ -134,7 +133,7 @@ Currently it only supports {pep}`681`, but [they intend](https://github.com/astr
134133
### Pyrefly
135134

136135
[Pyrefly] is Meta's take on a Rust-based type checker for Python.
137-
It also only implements {pep}`681` and based on the (lack of) activity on *attrs*-related issues on their bug tracker it doesn't seem like they have immediate ambition to do more than that at the moment.
136+
It also only implements {pep}`681` and based on the (lack of) activity on *attrs*-related issues on their bug tracker there is currently no indication that they plan to support additional *attrs* features.
138137

139138

140139
[Mypy]: http://mypy-lang.org

0 commit comments

Comments
 (0)