Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/libcst/_nodes/op.py: 84%

399 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-25 06:43 +0000

1# Copyright (c) Meta Platforms, Inc. and affiliates. 

2# 

3# This source code is licensed under the MIT license found in the 

4# LICENSE file in the root directory of this source tree. 

5 

6from abc import ABC, abstractmethod 

7from dataclasses import dataclass 

8from typing import Tuple 

9 

10from libcst._add_slots import add_slots 

11from libcst._nodes.base import BaseLeaf, CSTNode, CSTValidationError 

12from libcst._nodes.internal import CodegenState, visit_required 

13from libcst._nodes.whitespace import BaseParenthesizableWhitespace, SimpleWhitespace 

14from libcst._visitors import CSTVisitorT 

15 

16 

17class _BaseOneTokenOp(CSTNode, ABC): 

18 """ 

19 Any node that has a static value and needs to own whitespace on both sides. 

20 """ 

21 

22 __slots__ = () 

23 

24 whitespace_before: BaseParenthesizableWhitespace 

25 

26 whitespace_after: BaseParenthesizableWhitespace 

27 

28 def _visit_and_replace_children(self, visitor: CSTVisitorT) -> "_BaseOneTokenOp": 

29 # pyre-ignore Pyre thinks that self.__class__ is CSTNode, not _BaseOneTokenOp 

30 return self.__class__( 

31 whitespace_before=visit_required( 

32 self, "whitespace_before", self.whitespace_before, visitor 

33 ), 

34 whitespace_after=visit_required( 

35 self, "whitespace_after", self.whitespace_after, visitor 

36 ), 

37 ) 

38 

39 def _codegen_impl(self, state: CodegenState) -> None: 

40 self.whitespace_before._codegen(state) 

41 with state.record_syntactic_position(self): 

42 state.add_token(self._get_token()) 

43 self.whitespace_after._codegen(state) 

44 

45 @abstractmethod 

46 def _get_token(self) -> str: 

47 ... 

48 

49 

50class _BaseTwoTokenOp(CSTNode, ABC): 

51 """ 

52 Any node that ends up as two tokens, so we must preserve the whitespace 

53 in beteween them. 

54 """ 

55 

56 __slots__ = () 

57 

58 whitespace_before: BaseParenthesizableWhitespace 

59 

60 whitespace_between: BaseParenthesizableWhitespace 

61 

62 whitespace_after: BaseParenthesizableWhitespace 

63 

64 def _validate(self) -> None: 

65 if self.whitespace_between.empty: 

66 raise CSTValidationError("Must have at least one space between not and in.") 

67 

68 def _visit_and_replace_children(self, visitor: CSTVisitorT) -> "_BaseTwoTokenOp": 

69 # pyre-ignore Pyre thinks that self.__class__ is CSTNode, not _BaseTwoTokenOp 

70 return self.__class__( 

71 whitespace_before=visit_required( 

72 self, "whitespace_before", self.whitespace_before, visitor 

73 ), 

74 whitespace_between=visit_required( 

75 self, "whitespace_between", self.whitespace_between, visitor 

76 ), 

77 whitespace_after=visit_required( 

78 self, "whitespace_after", self.whitespace_after, visitor 

79 ), 

80 ) 

81 

82 def _codegen_impl(self, state: CodegenState) -> None: 

83 self.whitespace_before._codegen(state) 

84 with state.record_syntactic_position(self): 

85 state.add_token(self._get_tokens()[0]) 

86 self.whitespace_between._codegen(state) 

87 state.add_token(self._get_tokens()[1]) 

88 self.whitespace_after._codegen(state) 

89 

90 @abstractmethod 

91 def _get_tokens(self) -> Tuple[str, str]: 

92 ... 

93 

94 

95class BaseUnaryOp(CSTNode, ABC): 

96 """ 

97 Any node that has a static value used in a :class:`UnaryOperation` expression. 

98 """ 

99 

100 __slots__ = () 

101 

102 #: Any space that appears directly after this operator. 

103 whitespace_after: BaseParenthesizableWhitespace 

104 

105 def _visit_and_replace_children(self, visitor: CSTVisitorT) -> "BaseUnaryOp": 

106 # pyre-ignore Pyre thinks that self.__class__ is CSTNode, not BaseUnaryOp 

107 return self.__class__( 

108 whitespace_after=visit_required( 

109 self, "whitespace_after", self.whitespace_after, visitor 

110 ) 

111 ) 

112 

113 def _codegen_impl(self, state: CodegenState) -> None: 

114 state.add_token(self._get_token()) 

115 self.whitespace_after._codegen(state) 

116 

117 @abstractmethod 

118 def _get_token(self) -> str: 

119 ... 

120 

121 

122class BaseBooleanOp(_BaseOneTokenOp, ABC): 

123 """ 

124 Any node that has a static value used in a :class:`BooleanOperation` expression. 

125 This node is purely for typing. 

126 """ 

127 

128 __slots__ = () 

129 

130 

131class BaseBinaryOp(CSTNode, ABC): 

132 """ 

133 Any node that has a static value used in a :class:`BinaryOperation` expression. 

134 This node is purely for typing. 

135 """ 

136 

137 __slots__ = () 

138 

139 

140class BaseCompOp(CSTNode, ABC): 

141 """ 

142 Any node that has a static value used in a :class:`Comparison` expression. 

143 This node is purely for typing. 

144 """ 

145 

146 __slots__ = () 

147 

148 

149class BaseAugOp(CSTNode, ABC): 

150 """ 

151 Any node that has a static value used in an :class:`AugAssign` assignment. 

152 This node is purely for typing. 

153 """ 

154 

155 __slots__ = () 

156 

157 

158@add_slots 

159@dataclass(frozen=True) 

160class Semicolon(_BaseOneTokenOp): 

161 """ 

162 Used by any small statement (any subclass of :class:`BaseSmallStatement` 

163 such as :class:`Pass`) as a separator between subsequent nodes contained 

164 within a :class:`SimpleStatementLine` or :class:`SimpleStatementSuite`. 

165 """ 

166 

167 #: Any space that appears directly before this semicolon. 

168 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field("") 

169 

170 #: Any space that appears directly after this semicolon. 

171 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field("") 

172 

173 def _get_token(self) -> str: 

174 return ";" 

175 

176 

177@add_slots 

178@dataclass(frozen=True) 

179class Colon(_BaseOneTokenOp): 

180 """ 

181 Used by :class:`Slice` as a separator between subsequent expressions, 

182 and in :class:`Lambda` to separate arguments and body. 

183 """ 

184 

185 #: Any space that appears directly before this colon. 

186 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field("") 

187 

188 #: Any space that appears directly after this colon. 

189 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field("") 

190 

191 def _get_token(self) -> str: 

192 return ":" 

193 

194 

195@add_slots 

196@dataclass(frozen=True) 

197class Comma(_BaseOneTokenOp): 

198 """ 

199 Syntactic trivia used as a separator between subsequent items in various 

200 parts of the grammar. 

201 

202 Some use-cases are: 

203 

204 * :class:`Import` or :class:`ImportFrom`. 

205 * :class:`FunctionDef` arguments. 

206 * :class:`Tuple`/:class:`List`/:class:`Set`/:class:`Dict` elements. 

207 """ 

208 

209 #: Any space that appears directly before this comma. 

210 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field("") 

211 

212 #: Any space that appears directly after this comma. 

213 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field("") 

214 

215 def _get_token(self) -> str: 

216 return "," 

217 

218 

219@add_slots 

220@dataclass(frozen=True) 

221class Dot(_BaseOneTokenOp): 

222 """ 

223 Used by :class:`Attribute` as a separator between subsequent :class:`Name` nodes. 

224 """ 

225 

226 #: Any space that appears directly before this dot. 

227 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field("") 

228 

229 #: Any space that appears directly after this dot. 

230 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field("") 

231 

232 def _get_token(self) -> str: 

233 return "." 

234 

235 

236@add_slots 

237@dataclass(frozen=True) 

238class ImportStar(BaseLeaf): 

239 """ 

240 Used by :class:`ImportFrom` to denote a star import instead of a list 

241 of importable objects. 

242 """ 

243 

244 def _codegen_impl(self, state: CodegenState) -> None: 

245 state.add_token("*") 

246 

247 

248@add_slots 

249@dataclass(frozen=True) 

250class AssignEqual(_BaseOneTokenOp): 

251 """ 

252 Used by :class:`AnnAssign` to denote a single equal character when doing an 

253 assignment on top of a type annotation. Also used by :class:`Param` and 

254 :class:`Arg` to denote assignment of a default value, and by 

255 :class:`FormattedStringExpression` to denote usage of self-documenting 

256 expressions. 

257 """ 

258 

259 #: Any space that appears directly before this equal sign. 

260 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

261 

262 #: Any space that appears directly after this equal sign. 

263 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

264 

265 def _get_token(self) -> str: 

266 return "=" 

267 

268 

269@add_slots 

270@dataclass(frozen=True) 

271class Plus(BaseUnaryOp): 

272 """ 

273 A unary operator that can be used in a :class:`UnaryOperation` 

274 expression. 

275 """ 

276 

277 #: Any space that appears directly after this operator. 

278 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field("") 

279 

280 def _get_token(self) -> str: 

281 return "+" 

282 

283 

284@add_slots 

285@dataclass(frozen=True) 

286class Minus(BaseUnaryOp): 

287 """ 

288 A unary operator that can be used in a :class:`UnaryOperation` 

289 expression. 

290 """ 

291 

292 #: Any space that appears directly after this operator. 

293 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field("") 

294 

295 def _get_token(self) -> str: 

296 return "-" 

297 

298 

299@add_slots 

300@dataclass(frozen=True) 

301class BitInvert(BaseUnaryOp): 

302 """ 

303 A unary operator that can be used in a :class:`UnaryOperation` 

304 expression. 

305 """ 

306 

307 #: Any space that appears directly after this operator. 

308 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field("") 

309 

310 def _get_token(self) -> str: 

311 return "~" 

312 

313 

314@add_slots 

315@dataclass(frozen=True) 

316class Not(BaseUnaryOp): 

317 """ 

318 A unary operator that can be used in a :class:`UnaryOperation` 

319 expression. 

320 """ 

321 

322 #: Any space that appears directly after this operator. 

323 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

324 

325 def _get_token(self) -> str: 

326 return "not" 

327 

328 

329@add_slots 

330@dataclass(frozen=True) 

331class And(BaseBooleanOp): 

332 """ 

333 A boolean operator that can be used in a :class:`BooleanOperation` 

334 expression. 

335 """ 

336 

337 #: Any space that appears directly before this operator. 

338 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

339 

340 #: Any space that appears directly after this operator. 

341 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

342 

343 def _get_token(self) -> str: 

344 return "and" 

345 

346 

347@add_slots 

348@dataclass(frozen=True) 

349class Or(BaseBooleanOp): 

350 """ 

351 A boolean operator that can be used in a :class:`BooleanOperation` 

352 expression. 

353 """ 

354 

355 #: Any space that appears directly before this operator. 

356 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

357 

358 #: Any space that appears directly after this operator. 

359 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

360 

361 def _get_token(self) -> str: 

362 return "or" 

363 

364 

365@add_slots 

366@dataclass(frozen=True) 

367class Add(BaseBinaryOp, _BaseOneTokenOp): 

368 """ 

369 A binary operator that can be used in a :class:`BinaryOperation` 

370 expression. 

371 """ 

372 

373 #: Any space that appears directly before this operator. 

374 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

375 

376 #: Any space that appears directly after this operator. 

377 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

378 

379 def _get_token(self) -> str: 

380 return "+" 

381 

382 

383@add_slots 

384@dataclass(frozen=True) 

385class Subtract(BaseBinaryOp, _BaseOneTokenOp): 

386 """ 

387 A binary operator that can be used in a :class:`BinaryOperation` 

388 expression. 

389 """ 

390 

391 #: Any space that appears directly before this operator. 

392 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

393 

394 #: Any space that appears directly after this operator. 

395 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

396 

397 def _get_token(self) -> str: 

398 return "-" 

399 

400 

401@add_slots 

402@dataclass(frozen=True) 

403class Multiply(BaseBinaryOp, _BaseOneTokenOp): 

404 """ 

405 A binary operator that can be used in a :class:`BinaryOperation` 

406 expression. 

407 """ 

408 

409 #: Any space that appears directly before this operator. 

410 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

411 

412 #: Any space that appears directly after this operator. 

413 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

414 

415 def _get_token(self) -> str: 

416 return "*" 

417 

418 

419@add_slots 

420@dataclass(frozen=True) 

421class Divide(BaseBinaryOp, _BaseOneTokenOp): 

422 """ 

423 A binary operator that can be used in a :class:`BinaryOperation` 

424 expression. 

425 """ 

426 

427 #: Any space that appears directly before this operator. 

428 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

429 

430 #: Any space that appears directly after this operator. 

431 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

432 

433 def _get_token(self) -> str: 

434 return "/" 

435 

436 

437@add_slots 

438@dataclass(frozen=True) 

439class FloorDivide(BaseBinaryOp, _BaseOneTokenOp): 

440 """ 

441 A binary operator that can be used in a :class:`BinaryOperation` 

442 expression. 

443 """ 

444 

445 #: Any space that appears directly before this operator. 

446 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

447 

448 #: Any space that appears directly after this operator. 

449 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

450 

451 def _get_token(self) -> str: 

452 return "//" 

453 

454 

455@add_slots 

456@dataclass(frozen=True) 

457class Modulo(BaseBinaryOp, _BaseOneTokenOp): 

458 """ 

459 A binary operator that can be used in a :class:`BinaryOperation` 

460 expression. 

461 """ 

462 

463 #: Any space that appears directly before this operator. 

464 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

465 

466 #: Any space that appears directly after this operator. 

467 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

468 

469 def _get_token(self) -> str: 

470 return "%" 

471 

472 

473@add_slots 

474@dataclass(frozen=True) 

475class Power(BaseBinaryOp, _BaseOneTokenOp): 

476 """ 

477 A binary operator that can be used in a :class:`BinaryOperation` 

478 expression. 

479 """ 

480 

481 #: Any space that appears directly before this operator. 

482 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

483 

484 #: Any space that appears directly after this operator. 

485 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

486 

487 def _get_token(self) -> str: 

488 return "**" 

489 

490 

491@add_slots 

492@dataclass(frozen=True) 

493class LeftShift(BaseBinaryOp, _BaseOneTokenOp): 

494 """ 

495 A binary operator that can be used in a :class:`BinaryOperation` 

496 expression. 

497 """ 

498 

499 #: Any space that appears directly before this operator. 

500 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

501 

502 #: Any space that appears directly after this operator. 

503 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

504 

505 def _get_token(self) -> str: 

506 return "<<" 

507 

508 

509@add_slots 

510@dataclass(frozen=True) 

511class RightShift(BaseBinaryOp, _BaseOneTokenOp): 

512 """ 

513 A binary operator that can be used in a :class:`BinaryOperation` 

514 expression. 

515 """ 

516 

517 #: Any space that appears directly before this operator. 

518 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

519 

520 #: Any space that appears directly after this operator. 

521 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

522 

523 def _get_token(self) -> str: 

524 return ">>" 

525 

526 

527@add_slots 

528@dataclass(frozen=True) 

529class BitOr(BaseBinaryOp, _BaseOneTokenOp): 

530 """ 

531 A binary operator that can be used in a :class:`BinaryOperation` 

532 expression. 

533 """ 

534 

535 #: Any space that appears directly before this operator. 

536 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

537 

538 #: Any space that appears directly after this operator. 

539 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

540 

541 def _get_token(self) -> str: 

542 return "|" 

543 

544 

545@add_slots 

546@dataclass(frozen=True) 

547class BitAnd(BaseBinaryOp, _BaseOneTokenOp): 

548 """ 

549 A binary operator that can be used in a :class:`BinaryOperation` 

550 expression. 

551 """ 

552 

553 #: Any space that appears directly before this operator. 

554 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

555 

556 #: Any space that appears directly after this operator. 

557 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

558 

559 def _get_token(self) -> str: 

560 return "&" 

561 

562 

563@add_slots 

564@dataclass(frozen=True) 

565class BitXor(BaseBinaryOp, _BaseOneTokenOp): 

566 """ 

567 A binary operator that can be used in a :class:`BinaryOperation` 

568 expression. 

569 """ 

570 

571 #: Any space that appears directly before this operator. 

572 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

573 

574 #: Any space that appears directly after this operator. 

575 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

576 

577 def _get_token(self) -> str: 

578 return "^" 

579 

580 

581@add_slots 

582@dataclass(frozen=True) 

583class MatrixMultiply(BaseBinaryOp, _BaseOneTokenOp): 

584 """ 

585 A binary operator that can be used in a :class:`BinaryOperation` 

586 expression. 

587 """ 

588 

589 #: Any space that appears directly before this operator. 

590 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

591 

592 #: Any space that appears directly after this operator. 

593 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

594 

595 def _get_token(self) -> str: 

596 return "@" 

597 

598 

599@add_slots 

600@dataclass(frozen=True) 

601class LessThan(BaseCompOp, _BaseOneTokenOp): 

602 """ 

603 A comparision operator that can be used in a :class:`Comparison` expression. 

604 """ 

605 

606 #: Any space that appears directly before this operator. 

607 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

608 

609 #: Any space that appears directly after this operator. 

610 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

611 

612 def _get_token(self) -> str: 

613 return "<" 

614 

615 

616@add_slots 

617@dataclass(frozen=True) 

618class GreaterThan(BaseCompOp, _BaseOneTokenOp): 

619 """ 

620 A comparision operator that can be used in a :class:`Comparison` expression. 

621 """ 

622 

623 #: Any space that appears directly before this operator. 

624 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

625 

626 #: Any space that appears directly after this operator. 

627 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

628 

629 def _get_token(self) -> str: 

630 return ">" 

631 

632 

633@add_slots 

634@dataclass(frozen=True) 

635class Equal(BaseCompOp, _BaseOneTokenOp): 

636 """ 

637 A comparision operator that can be used in a :class:`Comparison` expression. 

638 """ 

639 

640 #: Any space that appears directly before this operator. 

641 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

642 

643 #: Any space that appears directly after this operator. 

644 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

645 

646 def _get_token(self) -> str: 

647 return "==" 

648 

649 

650@add_slots 

651@dataclass(frozen=True) 

652class LessThanEqual(BaseCompOp, _BaseOneTokenOp): 

653 """ 

654 A comparision operator that can be used in a :class:`Comparison` expression. 

655 """ 

656 

657 #: Any space that appears directly before this operator. 

658 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

659 

660 #: Any space that appears directly after this operator. 

661 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

662 

663 def _get_token(self) -> str: 

664 return "<=" 

665 

666 

667@add_slots 

668@dataclass(frozen=True) 

669class GreaterThanEqual(BaseCompOp, _BaseOneTokenOp): 

670 """ 

671 A comparision operator that can be used in a :class:`Comparison` expression. 

672 """ 

673 

674 #: Any space that appears directly before this operator. 

675 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

676 

677 #: Any space that appears directly after this operator. 

678 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

679 

680 def _get_token(self) -> str: 

681 return ">=" 

682 

683 

684@add_slots 

685@dataclass(frozen=True) 

686class NotEqual(BaseCompOp, _BaseOneTokenOp): 

687 """ 

688 A comparison operator that can be used in a :class:`Comparison` expression. 

689 

690 This node defines a static value for convenience, but in reality due to 

691 PEP 401 it can be one of two values, both of which should be a 

692 :class:`NotEqual` :class:`Comparison` operator. 

693 """ 

694 

695 #: The actual text value of this operator. Can be either ``!=`` or ``<>``. 

696 value: str = "!=" 

697 

698 #: Any space that appears directly before this operator. 

699 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

700 

701 #: Any space that appears directly after this operator. 

702 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

703 

704 def _validate(self) -> None: 

705 if self.value not in ["!=", "<>"]: 

706 raise CSTValidationError("Invalid value for NotEqual node.") 

707 

708 def _visit_and_replace_children(self, visitor: CSTVisitorT) -> "NotEqual": 

709 return self.__class__( 

710 whitespace_before=visit_required( 

711 self, "whitespace_before", self.whitespace_before, visitor 

712 ), 

713 value=self.value, 

714 whitespace_after=visit_required( 

715 self, "whitespace_after", self.whitespace_after, visitor 

716 ), 

717 ) 

718 

719 def _get_token(self) -> str: 

720 return self.value 

721 

722 

723@add_slots 

724@dataclass(frozen=True) 

725class In(BaseCompOp, _BaseOneTokenOp): 

726 """ 

727 A comparision operator that can be used in a :class:`Comparison` expression. 

728 """ 

729 

730 #: Any space that appears directly before this operator. 

731 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

732 

733 #: Any space that appears directly after this operator. 

734 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

735 

736 def _get_token(self) -> str: 

737 return "in" 

738 

739 

740@add_slots 

741@dataclass(frozen=True) 

742class NotIn(BaseCompOp, _BaseTwoTokenOp): 

743 """ 

744 A comparision operator that can be used in a :class:`Comparison` expression. 

745 

746 This operator spans two tokens that must be separated by at least one space, 

747 so there is a third whitespace attribute to represent this. 

748 """ 

749 

750 #: Any space that appears directly before this operator. 

751 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

752 

753 #: Any space that appears between the ``not`` and ``in`` tokens. 

754 whitespace_between: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

755 

756 #: Any space that appears directly after this operator. 

757 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

758 

759 def _get_tokens(self) -> Tuple[str, str]: 

760 return ("not", "in") 

761 

762 

763@add_slots 

764@dataclass(frozen=True) 

765class Is(BaseCompOp, _BaseOneTokenOp): 

766 """ 

767 A comparision operator that can be used in a :class:`Comparison` expression. 

768 """ 

769 

770 #: Any space that appears directly before this operator. 

771 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

772 

773 #: Any space that appears directly after this operator. 

774 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

775 

776 def _get_token(self) -> str: 

777 return "is" 

778 

779 

780@add_slots 

781@dataclass(frozen=True) 

782class IsNot(BaseCompOp, _BaseTwoTokenOp): 

783 """ 

784 A comparision operator that can be used in a :class:`Comparison` expression. 

785 

786 This operator spans two tokens that must be separated by at least one space, 

787 so there is a third whitespace attribute to represent this. 

788 """ 

789 

790 #: Any space that appears directly before this operator. 

791 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

792 

793 #: Any space that appears between the ``is`` and ``not`` tokens. 

794 whitespace_between: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

795 

796 #: Any space that appears directly after this operator. 

797 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

798 

799 def _get_tokens(self) -> Tuple[str, str]: 

800 return ("is", "not") 

801 

802 

803@add_slots 

804@dataclass(frozen=True) 

805class AddAssign(BaseAugOp, _BaseOneTokenOp): 

806 """ 

807 An augmented assignment operator that can be used in a :class:`AugAssign` 

808 statement. 

809 """ 

810 

811 #: Any space that appears directly before this operator. 

812 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

813 

814 #: Any space that appears directly after this operator. 

815 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

816 

817 def _get_token(self) -> str: 

818 return "+=" 

819 

820 

821@add_slots 

822@dataclass(frozen=True) 

823class SubtractAssign(BaseAugOp, _BaseOneTokenOp): 

824 """ 

825 An augmented assignment operator that can be used in a :class:`AugAssign` 

826 statement. 

827 """ 

828 

829 #: Any space that appears directly before this operator. 

830 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

831 

832 #: Any space that appears directly after this operator. 

833 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

834 

835 def _get_token(self) -> str: 

836 return "-=" 

837 

838 

839@add_slots 

840@dataclass(frozen=True) 

841class MultiplyAssign(BaseAugOp, _BaseOneTokenOp): 

842 """ 

843 An augmented assignment operator that can be used in a :class:`AugAssign` 

844 statement. 

845 """ 

846 

847 #: Any space that appears directly before this operator. 

848 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

849 

850 #: Any space that appears directly after this operator. 

851 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

852 

853 def _get_token(self) -> str: 

854 return "*=" 

855 

856 

857@add_slots 

858@dataclass(frozen=True) 

859class MatrixMultiplyAssign(BaseAugOp, _BaseOneTokenOp): 

860 """ 

861 An augmented assignment operator that can be used in a :class:`AugAssign` 

862 statement. 

863 """ 

864 

865 #: Any space that appears directly before this operator. 

866 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

867 

868 #: Any space that appears directly after this operator. 

869 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

870 

871 def _get_token(self) -> str: 

872 return "@=" 

873 

874 

875@add_slots 

876@dataclass(frozen=True) 

877class DivideAssign(BaseAugOp, _BaseOneTokenOp): 

878 """ 

879 An augmented assignment operator that can be used in a :class:`AugAssign` 

880 statement. 

881 """ 

882 

883 #: Any space that appears directly before this operator. 

884 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

885 

886 #: Any space that appears directly after this operator. 

887 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

888 

889 def _get_token(self) -> str: 

890 return "/=" 

891 

892 

893@add_slots 

894@dataclass(frozen=True) 

895class ModuloAssign(BaseAugOp, _BaseOneTokenOp): 

896 """ 

897 An augmented assignment operator that can be used in a :class:`AugAssign` 

898 statement. 

899 """ 

900 

901 #: Any space that appears directly before this operator. 

902 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

903 

904 #: Any space that appears directly after this operator. 

905 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

906 

907 def _get_token(self) -> str: 

908 return "%=" 

909 

910 

911@add_slots 

912@dataclass(frozen=True) 

913class BitAndAssign(BaseAugOp, _BaseOneTokenOp): 

914 """ 

915 An augmented assignment operator that can be used in a :class:`AugAssign` 

916 statement. 

917 """ 

918 

919 #: Any space that appears directly before this operator. 

920 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

921 

922 #: Any space that appears directly after this operator. 

923 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

924 

925 def _get_token(self) -> str: 

926 return "&=" 

927 

928 

929@add_slots 

930@dataclass(frozen=True) 

931class BitOrAssign(BaseAugOp, _BaseOneTokenOp): 

932 """ 

933 An augmented assignment operator that can be used in a :class:`AugAssign` 

934 statement. 

935 """ 

936 

937 #: Any space that appears directly before this operator. 

938 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

939 

940 #: Any space that appears directly after this operator. 

941 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

942 

943 def _get_token(self) -> str: 

944 return "|=" 

945 

946 

947@add_slots 

948@dataclass(frozen=True) 

949class BitXorAssign(BaseAugOp, _BaseOneTokenOp): 

950 """ 

951 An augmented assignment operator that can be used in a :class:`AugAssign` 

952 statement. 

953 """ 

954 

955 #: Any space that appears directly before this operator. 

956 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

957 

958 #: Any space that appears directly after this operator. 

959 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

960 

961 def _get_token(self) -> str: 

962 return "^=" 

963 

964 

965@add_slots 

966@dataclass(frozen=True) 

967class LeftShiftAssign(BaseAugOp, _BaseOneTokenOp): 

968 """ 

969 An augmented assignment operator that can be used in a :class:`AugAssign` 

970 statement. 

971 """ 

972 

973 #: Any space that appears directly before this operator. 

974 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

975 

976 #: Any space that appears directly after this operator. 

977 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

978 

979 def _get_token(self) -> str: 

980 return "<<=" 

981 

982 

983@add_slots 

984@dataclass(frozen=True) 

985class RightShiftAssign(BaseAugOp, _BaseOneTokenOp): 

986 """ 

987 An augmented assignment operator that can be used in a :class:`AugAssign` 

988 statement. 

989 """ 

990 

991 #: Any space that appears directly before this operator. 

992 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

993 

994 #: Any space that appears directly after this operator. 

995 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

996 

997 def _get_token(self) -> str: 

998 return ">>=" 

999 

1000 

1001@add_slots 

1002@dataclass(frozen=True) 

1003class PowerAssign(BaseAugOp, _BaseOneTokenOp): 

1004 """ 

1005 An augmented assignment operator that can be used in a :class:`AugAssign` 

1006 statement. 

1007 """ 

1008 

1009 #: Any space that appears directly before this operator. 

1010 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

1011 

1012 #: Any space that appears directly after this operator. 

1013 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

1014 

1015 def _get_token(self) -> str: 

1016 return "**=" 

1017 

1018 

1019@add_slots 

1020@dataclass(frozen=True) 

1021class FloorDivideAssign(BaseAugOp, _BaseOneTokenOp): 

1022 """ 

1023 An augmented assignment operator that can be used in a :class:`AugAssign` 

1024 statement. 

1025 """ 

1026 

1027 #: Any space that appears directly before this operator. 

1028 whitespace_before: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

1029 

1030 #: Any space that appears directly after this operator. 

1031 whitespace_after: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") 

1032 

1033 def _get_token(self) -> str: 

1034 return "//="