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

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

397 statements  

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 

49class _BaseTwoTokenOp(CSTNode, ABC): 

50 """ 

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

52 in beteween them. 

53 """ 

54 

55 __slots__ = () 

56 

57 whitespace_before: BaseParenthesizableWhitespace 

58 

59 whitespace_between: BaseParenthesizableWhitespace 

60 

61 whitespace_after: BaseParenthesizableWhitespace 

62 

63 def _validate(self) -> None: 

64 if self.whitespace_between.empty: 

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

66 

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

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

69 return self.__class__( 

70 whitespace_before=visit_required( 

71 self, "whitespace_before", self.whitespace_before, visitor 

72 ), 

73 whitespace_between=visit_required( 

74 self, "whitespace_between", self.whitespace_between, visitor 

75 ), 

76 whitespace_after=visit_required( 

77 self, "whitespace_after", self.whitespace_after, visitor 

78 ), 

79 ) 

80 

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

82 self.whitespace_before._codegen(state) 

83 with state.record_syntactic_position(self): 

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

85 self.whitespace_between._codegen(state) 

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

87 self.whitespace_after._codegen(state) 

88 

89 @abstractmethod 

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

91 

92 

93class BaseUnaryOp(CSTNode, ABC): 

94 """ 

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

96 """ 

97 

98 __slots__ = () 

99 

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

101 whitespace_after: BaseParenthesizableWhitespace 

102 

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

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

105 return self.__class__( 

106 whitespace_after=visit_required( 

107 self, "whitespace_after", self.whitespace_after, visitor 

108 ) 

109 ) 

110 

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

112 state.add_token(self._get_token()) 

113 self.whitespace_after._codegen(state) 

114 

115 @abstractmethod 

116 def _get_token(self) -> str: ... 

117 

118 

119class BaseBooleanOp(_BaseOneTokenOp, ABC): 

120 """ 

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

122 This node is purely for typing. 

123 """ 

124 

125 __slots__ = () 

126 

127 

128class BaseBinaryOp(CSTNode, ABC): 

129 """ 

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

131 This node is purely for typing. 

132 """ 

133 

134 __slots__ = () 

135 

136 

137class BaseCompOp(CSTNode, ABC): 

138 """ 

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

140 This node is purely for typing. 

141 """ 

142 

143 __slots__ = () 

144 

145 

146class BaseAugOp(CSTNode, ABC): 

147 """ 

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

149 This node is purely for typing. 

150 """ 

151 

152 __slots__ = () 

153 

154 

155@add_slots 

156@dataclass(frozen=True) 

157class Semicolon(_BaseOneTokenOp): 

158 """ 

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

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

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

162 """ 

163 

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

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

166 

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

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

169 

170 def _get_token(self) -> str: 

171 return ";" 

172 

173 

174@add_slots 

175@dataclass(frozen=True) 

176class Colon(_BaseOneTokenOp): 

177 """ 

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

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

180 """ 

181 

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

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

184 

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

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

187 

188 def _get_token(self) -> str: 

189 return ":" 

190 

191 

192@add_slots 

193@dataclass(frozen=True) 

194class Comma(_BaseOneTokenOp): 

195 """ 

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

197 parts of the grammar. 

198 

199 Some use-cases are: 

200 

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

202 * :class:`FunctionDef` arguments. 

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

204 """ 

205 

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

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

208 

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

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

211 

212 def _get_token(self) -> str: 

213 return "," 

214 

215 

216@add_slots 

217@dataclass(frozen=True) 

218class Dot(_BaseOneTokenOp): 

219 """ 

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

221 """ 

222 

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

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

225 

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

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

228 

229 def _get_token(self) -> str: 

230 return "." 

231 

232 

233@add_slots 

234@dataclass(frozen=True) 

235class ImportStar(BaseLeaf): 

236 """ 

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

238 of importable objects. 

239 """ 

240 

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

242 state.add_token("*") 

243 

244 

245@add_slots 

246@dataclass(frozen=True) 

247class AssignEqual(_BaseOneTokenOp): 

248 """ 

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

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

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

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

253 expressions. 

254 """ 

255 

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

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

258 

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

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

261 

262 def _get_token(self) -> str: 

263 return "=" 

264 

265 

266@add_slots 

267@dataclass(frozen=True) 

268class Plus(BaseUnaryOp): 

269 """ 

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

271 expression. 

272 """ 

273 

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

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

276 

277 def _get_token(self) -> str: 

278 return "+" 

279 

280 

281@add_slots 

282@dataclass(frozen=True) 

283class Minus(BaseUnaryOp): 

284 """ 

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

286 expression. 

287 """ 

288 

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

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

291 

292 def _get_token(self) -> str: 

293 return "-" 

294 

295 

296@add_slots 

297@dataclass(frozen=True) 

298class BitInvert(BaseUnaryOp): 

299 """ 

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

301 expression. 

302 """ 

303 

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

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

306 

307 def _get_token(self) -> str: 

308 return "~" 

309 

310 

311@add_slots 

312@dataclass(frozen=True) 

313class Not(BaseUnaryOp): 

314 """ 

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

316 expression. 

317 """ 

318 

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

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

321 

322 def _get_token(self) -> str: 

323 return "not" 

324 

325 

326@add_slots 

327@dataclass(frozen=True) 

328class And(BaseBooleanOp): 

329 """ 

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

331 expression. 

332 """ 

333 

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

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

336 

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

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

339 

340 def _get_token(self) -> str: 

341 return "and" 

342 

343 

344@add_slots 

345@dataclass(frozen=True) 

346class Or(BaseBooleanOp): 

347 """ 

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

349 expression. 

350 """ 

351 

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

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

354 

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

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

357 

358 def _get_token(self) -> str: 

359 return "or" 

360 

361 

362@add_slots 

363@dataclass(frozen=True) 

364class Add(BaseBinaryOp, _BaseOneTokenOp): 

365 """ 

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

367 expression. 

368 """ 

369 

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

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

372 

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

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

375 

376 def _get_token(self) -> str: 

377 return "+" 

378 

379 

380@add_slots 

381@dataclass(frozen=True) 

382class Subtract(BaseBinaryOp, _BaseOneTokenOp): 

383 """ 

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

385 expression. 

386 """ 

387 

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

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

390 

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

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

393 

394 def _get_token(self) -> str: 

395 return "-" 

396 

397 

398@add_slots 

399@dataclass(frozen=True) 

400class Multiply(BaseBinaryOp, _BaseOneTokenOp): 

401 """ 

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

403 expression. 

404 """ 

405 

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

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

408 

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

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

411 

412 def _get_token(self) -> str: 

413 return "*" 

414 

415 

416@add_slots 

417@dataclass(frozen=True) 

418class Divide(BaseBinaryOp, _BaseOneTokenOp): 

419 """ 

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

421 expression. 

422 """ 

423 

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

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

426 

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

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

429 

430 def _get_token(self) -> str: 

431 return "/" 

432 

433 

434@add_slots 

435@dataclass(frozen=True) 

436class FloorDivide(BaseBinaryOp, _BaseOneTokenOp): 

437 """ 

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

439 expression. 

440 """ 

441 

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

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

444 

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

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

447 

448 def _get_token(self) -> str: 

449 return "//" 

450 

451 

452@add_slots 

453@dataclass(frozen=True) 

454class Modulo(BaseBinaryOp, _BaseOneTokenOp): 

455 """ 

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

457 expression. 

458 """ 

459 

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

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

462 

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

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

465 

466 def _get_token(self) -> str: 

467 return "%" 

468 

469 

470@add_slots 

471@dataclass(frozen=True) 

472class Power(BaseBinaryOp, _BaseOneTokenOp): 

473 """ 

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

475 expression. 

476 """ 

477 

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

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

480 

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

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

483 

484 def _get_token(self) -> str: 

485 return "**" 

486 

487 

488@add_slots 

489@dataclass(frozen=True) 

490class LeftShift(BaseBinaryOp, _BaseOneTokenOp): 

491 """ 

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

493 expression. 

494 """ 

495 

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

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

498 

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

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

501 

502 def _get_token(self) -> str: 

503 return "<<" 

504 

505 

506@add_slots 

507@dataclass(frozen=True) 

508class RightShift(BaseBinaryOp, _BaseOneTokenOp): 

509 """ 

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

511 expression. 

512 """ 

513 

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

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

516 

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

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

519 

520 def _get_token(self) -> str: 

521 return ">>" 

522 

523 

524@add_slots 

525@dataclass(frozen=True) 

526class BitOr(BaseBinaryOp, _BaseOneTokenOp): 

527 """ 

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

529 expression. 

530 """ 

531 

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

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

534 

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

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

537 

538 def _get_token(self) -> str: 

539 return "|" 

540 

541 

542@add_slots 

543@dataclass(frozen=True) 

544class BitAnd(BaseBinaryOp, _BaseOneTokenOp): 

545 """ 

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

547 expression. 

548 """ 

549 

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

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

552 

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

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

555 

556 def _get_token(self) -> str: 

557 return "&" 

558 

559 

560@add_slots 

561@dataclass(frozen=True) 

562class BitXor(BaseBinaryOp, _BaseOneTokenOp): 

563 """ 

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

565 expression. 

566 """ 

567 

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

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

570 

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

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

573 

574 def _get_token(self) -> str: 

575 return "^" 

576 

577 

578@add_slots 

579@dataclass(frozen=True) 

580class MatrixMultiply(BaseBinaryOp, _BaseOneTokenOp): 

581 """ 

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

583 expression. 

584 """ 

585 

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

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

588 

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

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

591 

592 def _get_token(self) -> str: 

593 return "@" 

594 

595 

596@add_slots 

597@dataclass(frozen=True) 

598class LessThan(BaseCompOp, _BaseOneTokenOp): 

599 """ 

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

601 """ 

602 

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

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

605 

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

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

608 

609 def _get_token(self) -> str: 

610 return "<" 

611 

612 

613@add_slots 

614@dataclass(frozen=True) 

615class GreaterThan(BaseCompOp, _BaseOneTokenOp): 

616 """ 

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

618 """ 

619 

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

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

622 

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

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

625 

626 def _get_token(self) -> str: 

627 return ">" 

628 

629 

630@add_slots 

631@dataclass(frozen=True) 

632class Equal(BaseCompOp, _BaseOneTokenOp): 

633 """ 

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

635 """ 

636 

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

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

639 

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

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

642 

643 def _get_token(self) -> str: 

644 return "==" 

645 

646 

647@add_slots 

648@dataclass(frozen=True) 

649class LessThanEqual(BaseCompOp, _BaseOneTokenOp): 

650 """ 

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

652 """ 

653 

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

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

656 

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

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

659 

660 def _get_token(self) -> str: 

661 return "<=" 

662 

663 

664@add_slots 

665@dataclass(frozen=True) 

666class GreaterThanEqual(BaseCompOp, _BaseOneTokenOp): 

667 """ 

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

669 """ 

670 

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

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

673 

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

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

676 

677 def _get_token(self) -> str: 

678 return ">=" 

679 

680 

681@add_slots 

682@dataclass(frozen=True) 

683class NotEqual(BaseCompOp, _BaseOneTokenOp): 

684 """ 

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

686 

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

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

689 :class:`NotEqual` :class:`Comparison` operator. 

690 """ 

691 

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

693 value: str = "!=" 

694 

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

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

697 

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

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

700 

701 def _validate(self) -> None: 

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

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

704 

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

706 return self.__class__( 

707 whitespace_before=visit_required( 

708 self, "whitespace_before", self.whitespace_before, visitor 

709 ), 

710 value=self.value, 

711 whitespace_after=visit_required( 

712 self, "whitespace_after", self.whitespace_after, visitor 

713 ), 

714 ) 

715 

716 def _get_token(self) -> str: 

717 return self.value 

718 

719 

720@add_slots 

721@dataclass(frozen=True) 

722class In(BaseCompOp, _BaseOneTokenOp): 

723 """ 

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

725 """ 

726 

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

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

729 

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

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

732 

733 def _get_token(self) -> str: 

734 return "in" 

735 

736 

737@add_slots 

738@dataclass(frozen=True) 

739class NotIn(BaseCompOp, _BaseTwoTokenOp): 

740 """ 

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

742 

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

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

745 """ 

746 

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

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

749 

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

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

752 

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

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

755 

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

757 return ("not", "in") 

758 

759 

760@add_slots 

761@dataclass(frozen=True) 

762class Is(BaseCompOp, _BaseOneTokenOp): 

763 """ 

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

765 """ 

766 

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

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

769 

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

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

772 

773 def _get_token(self) -> str: 

774 return "is" 

775 

776 

777@add_slots 

778@dataclass(frozen=True) 

779class IsNot(BaseCompOp, _BaseTwoTokenOp): 

780 """ 

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

782 

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

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

785 """ 

786 

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

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

789 

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

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

792 

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

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

795 

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

797 return ("is", "not") 

798 

799 

800@add_slots 

801@dataclass(frozen=True) 

802class AddAssign(BaseAugOp, _BaseOneTokenOp): 

803 """ 

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

805 statement. 

806 """ 

807 

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

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

810 

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

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

813 

814 def _get_token(self) -> str: 

815 return "+=" 

816 

817 

818@add_slots 

819@dataclass(frozen=True) 

820class SubtractAssign(BaseAugOp, _BaseOneTokenOp): 

821 """ 

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

823 statement. 

824 """ 

825 

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

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

828 

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

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

831 

832 def _get_token(self) -> str: 

833 return "-=" 

834 

835 

836@add_slots 

837@dataclass(frozen=True) 

838class MultiplyAssign(BaseAugOp, _BaseOneTokenOp): 

839 """ 

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

841 statement. 

842 """ 

843 

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

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

846 

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

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

849 

850 def _get_token(self) -> str: 

851 return "*=" 

852 

853 

854@add_slots 

855@dataclass(frozen=True) 

856class MatrixMultiplyAssign(BaseAugOp, _BaseOneTokenOp): 

857 """ 

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

859 statement. 

860 """ 

861 

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

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

864 

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

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

867 

868 def _get_token(self) -> str: 

869 return "@=" 

870 

871 

872@add_slots 

873@dataclass(frozen=True) 

874class DivideAssign(BaseAugOp, _BaseOneTokenOp): 

875 """ 

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

877 statement. 

878 """ 

879 

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

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

882 

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

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

885 

886 def _get_token(self) -> str: 

887 return "/=" 

888 

889 

890@add_slots 

891@dataclass(frozen=True) 

892class ModuloAssign(BaseAugOp, _BaseOneTokenOp): 

893 """ 

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

895 statement. 

896 """ 

897 

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

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

900 

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

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

903 

904 def _get_token(self) -> str: 

905 return "%=" 

906 

907 

908@add_slots 

909@dataclass(frozen=True) 

910class BitAndAssign(BaseAugOp, _BaseOneTokenOp): 

911 """ 

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

913 statement. 

914 """ 

915 

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

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

918 

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

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

921 

922 def _get_token(self) -> str: 

923 return "&=" 

924 

925 

926@add_slots 

927@dataclass(frozen=True) 

928class BitOrAssign(BaseAugOp, _BaseOneTokenOp): 

929 """ 

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

931 statement. 

932 """ 

933 

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

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

936 

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

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

939 

940 def _get_token(self) -> str: 

941 return "|=" 

942 

943 

944@add_slots 

945@dataclass(frozen=True) 

946class BitXorAssign(BaseAugOp, _BaseOneTokenOp): 

947 """ 

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

949 statement. 

950 """ 

951 

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

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

954 

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

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

957 

958 def _get_token(self) -> str: 

959 return "^=" 

960 

961 

962@add_slots 

963@dataclass(frozen=True) 

964class LeftShiftAssign(BaseAugOp, _BaseOneTokenOp): 

965 """ 

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

967 statement. 

968 """ 

969 

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

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

972 

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

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

975 

976 def _get_token(self) -> str: 

977 return "<<=" 

978 

979 

980@add_slots 

981@dataclass(frozen=True) 

982class RightShiftAssign(BaseAugOp, _BaseOneTokenOp): 

983 """ 

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

985 statement. 

986 """ 

987 

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

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

990 

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

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

993 

994 def _get_token(self) -> str: 

995 return ">>=" 

996 

997 

998@add_slots 

999@dataclass(frozen=True) 

1000class PowerAssign(BaseAugOp, _BaseOneTokenOp): 

1001 """ 

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

1003 statement. 

1004 """ 

1005 

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

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

1008 

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

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

1011 

1012 def _get_token(self) -> str: 

1013 return "**=" 

1014 

1015 

1016@add_slots 

1017@dataclass(frozen=True) 

1018class FloorDivideAssign(BaseAugOp, _BaseOneTokenOp): 

1019 """ 

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

1021 statement. 

1022 """ 

1023 

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

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

1026 

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

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

1029 

1030 def _get_token(self) -> str: 

1031 return "//="