Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ reveal_type(C().FINAL_D) # revealed: Literal[1]
reveal_type(C().FINAL_E) # revealed: int
```

### Recursive bare `Final` instance attribute

```py
from __future__ import annotations

from typing import Final

class ScopeChain:
def __init__(self, parent: ScopeChain | None = None) -> None:
self.depth: Final = 1 if parent is None else parent.depth + 1
```

## Not modifiable

### Names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::types::cyclic::CycleDetector;
use crate::types::diagnostic::{
DIVISION_BY_ZERO, report_unsupported_augmented_assignment, report_unsupported_binary_operation,
};
use crate::types::set_theoretic::RecursivelyDefined;
use crate::types::typevar::TypeVarConstraints;
use crate::types::{
DynamicType, InternedConstraintSet, KnownClass, KnownInstanceType, LiteralValueTypeKind,
Expand Down Expand Up @@ -550,7 +551,14 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
(Type::Never, _, _) | (_, Type::Never, _) => Some(Type::Never),

(Type::LiteralValue(left), Type::LiteralValue(right), _) => {
match (left.kind(), right.kind(), op) {
let recursively_defined = if left.recursively_defined().is_yes()
|| right.recursively_defined().is_yes()
{
RecursivelyDefined::Yes
} else {
RecursivelyDefined::No
};
let result = match (left.kind(), right.kind(), op) {
(
LiteralValueTypeKind::Int(n),
LiteralValueTypeKind::Int(m),
Expand Down Expand Up @@ -827,7 +835,14 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
}

_ => Type::try_call_bin_op_return_type(db, left_ty, op, right_ty),
}
};

result.map(|result| match result {
Type::LiteralValue(literal) => {
Type::LiteralValue(literal.with_recursively_defined(recursively_defined))
}
_ => result,
})
}

(
Expand Down
Loading