Compare commits
1 Commits
david/data
...
micha/sema
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da6403b1bf |
@@ -242,6 +242,22 @@ mod tests {
|
||||
}
|
||||
|
||||
pub(super) fn render_diagnostics<I, D>(&self, diagnostics: I) -> String
|
||||
where
|
||||
I: IntoIterator<Item = D>,
|
||||
D: IntoDiagnostic,
|
||||
{
|
||||
let config = DisplayDiagnosticConfig::default()
|
||||
.color(false)
|
||||
.format(DiagnosticFormat::Full);
|
||||
|
||||
self.render_diagnostics_with_config(diagnostics, &config)
|
||||
}
|
||||
|
||||
pub(super) fn render_diagnostics_with_config<I, D>(
|
||||
&self,
|
||||
diagnostics: I,
|
||||
config: &DisplayDiagnosticConfig,
|
||||
) -> String
|
||||
where
|
||||
I: IntoIterator<Item = D>,
|
||||
D: IntoDiagnostic,
|
||||
@@ -250,12 +266,9 @@ mod tests {
|
||||
|
||||
let mut buf = String::new();
|
||||
|
||||
let config = DisplayDiagnosticConfig::default()
|
||||
.color(false)
|
||||
.format(DiagnosticFormat::Full);
|
||||
for diagnostic in diagnostics {
|
||||
let diag = diagnostic.into_diagnostic();
|
||||
write!(buf, "{}", diag.display(&self.db, &config)).unwrap();
|
||||
write!(buf, "{}", diag.display(&self.db, config)).unwrap();
|
||||
}
|
||||
|
||||
buf
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1787,7 +1787,7 @@ date.day = 8
|
||||
date.month = 4
|
||||
date.year = 2025
|
||||
|
||||
# error: [unresolved-attribute] "Can not assign object of type `Literal["UTC"]` to attribute `tz` on type `Date` with custom `__setattr__` method."
|
||||
# error: [unresolved-attribute] "Can not assign object of `Literal["UTC"]` to attribute `tz` on type `Date` with custom `__setattr__` method."
|
||||
date.tz = "UTC"
|
||||
```
|
||||
|
||||
|
||||
@@ -444,33 +444,6 @@ To do
|
||||
|
||||
To do
|
||||
|
||||
## `Final` fields
|
||||
|
||||
Dataclass fields can be annotated with `Final`, which means that the field cannot be reassigned
|
||||
after the instance is created. Fields that are additionally annotated with `ClassVar` are not part
|
||||
of the `__init__` signature.
|
||||
|
||||
```py
|
||||
from dataclasses import dataclass
|
||||
from typing import Final, ClassVar
|
||||
|
||||
@dataclass
|
||||
class C:
|
||||
# a `Final` annotation without a right-hand side is not allowed in normal classes,
|
||||
# but valid for dataclasses. The field will be initialized in the synthesized
|
||||
# `__init__` method
|
||||
instance_variable_no_default: Final[int]
|
||||
instance_variable: Final[int] = 1
|
||||
class_variable1: ClassVar[Final[int]] = 1
|
||||
class_variable2: ClassVar[Final[int]] = 1
|
||||
|
||||
reveal_type(C.__init__) # revealed: (self: C, instance_variable_no_default: int, instance_variable: int = Literal[1]) -> None
|
||||
|
||||
c = C(1)
|
||||
# TODO: this should be an error
|
||||
c.instance_variable = 2
|
||||
```
|
||||
|
||||
## Inheritance
|
||||
|
||||
### Normal class inheriting from a dataclass
|
||||
|
||||
@@ -162,10 +162,6 @@ from typing import Final
|
||||
|
||||
# TODO: This should be an error
|
||||
NO_RHS: Final
|
||||
|
||||
class C:
|
||||
# TODO: This should be an error
|
||||
NO_RHS: Final
|
||||
```
|
||||
|
||||
[`typing.final`]: https://docs.python.org/3/library/typing.html#typing.Final
|
||||
|
||||
@@ -3495,7 +3495,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
||||
self.context.report_lint(&UNRESOLVED_ATTRIBUTE, target)
|
||||
{
|
||||
builder.into_diagnostic(format_args!(
|
||||
"Can not assign object of type `{}` to attribute \
|
||||
"Can not assign object of `{}` to attribute \
|
||||
`{attribute}` on type `{}` with \
|
||||
custom `__setattr__` method.",
|
||||
value_ty.display(db),
|
||||
|
||||
Reference in New Issue
Block a user