You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// We interpret `self.foo = None` to mean the type of foo is None or some unknown type.
1739
1739
(None,Expr::NoneLiteral(_)) => {
1740
-
self.error(errors, x.range(),ErrorInfo::Kind(ErrorKind::ImplicitAny),"This expression is implicitly inferred to be `Any | None`. Please provide an explicit type annotation.".to_owned());
1740
+
self.error(errors, x.range(),ErrorInfo::Kind(ErrorKind::UnannotatedAttribute),"This expression is implicitly inferred to be `Any | None`. Please provide an explicit type annotation.".to_owned());
Copy file name to clipboardExpand all lines: website/docs/error-kinds.mdx
+16Lines changed: 16 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -975,6 +975,22 @@ if "abc":
975
975
976
976
Pyrefly uses this error to communicate the output of the [`reveal_type`](https://typing.python.org/en/latest/spec/directives.html#reveal-type) function.
977
977
978
+
## unannotated-attribute
979
+
980
+
This error is raised when a class attribute is missing a type annotation and is initialized with the `None` literal. Without an explicit annotation, Pyrefly infers the type as `Any | None`, which reduces type safety.
981
+
982
+
This error is off by default. To fix it, add an explicit type annotation to the attribute.
983
+
984
+
```python
985
+
classMyClass:
986
+
# error: This expression is implicitly inferred to be `Any | None`. Please provide an explicit type annotation.
987
+
value =None
988
+
989
+
# Fixed version:
990
+
classMyClass:
991
+
value: int|None=None
992
+
```
993
+
978
994
## unannotated-parameter
979
995
980
996
This error is raised when a function parameter is missing a type annotation. This helps enforce fully-typed codebases by ensuring all parameters have explicit types.
0 commit comments