| 496 | |
| 497 | impl Comparable for PyCode { |
| 498 | fn cmp( |
| 499 | zelf: &Py<Self>, |
| 500 | other: &PyObject, |
| 501 | op: crate::types::PyComparisonOp, |
| 502 | vm: &VirtualMachine, |
| 503 | ) -> PyResult<crate::function::PyComparisonValue> { |
| 504 | op.eq_only(|| { |
| 505 | let other = class_or_notimplemented!(Self, other); |
| 506 | let a = &zelf.code; |
| 507 | let b = &other.code; |
| 508 | let eq = a.obj_name == b.obj_name |
| 509 | && a.arg_count == b.arg_count |
| 510 | && a.posonlyarg_count == b.posonlyarg_count |
| 511 | && a.kwonlyarg_count == b.kwonlyarg_count |
| 512 | && a.flags == b.flags |
| 513 | && a.first_line_number == b.first_line_number |
| 514 | && a.instructions.original_bytes() == b.instructions.original_bytes() |
| 515 | && a.linetable == b.linetable |
| 516 | && a.exceptiontable == b.exceptiontable |
| 517 | && a.names == b.names |
| 518 | && a.varnames == b.varnames |
| 519 | && a.freevars == b.freevars |
| 520 | && a.cellvars == b.cellvars |
| 521 | && { |
| 522 | let a_consts: Vec<_> = a.constants.iter().map(|c| c.0.clone()).collect(); |
| 523 | let b_consts: Vec<_> = b.constants.iter().map(|c| c.0.clone()).collect(); |
| 524 | if a_consts.len() != b_consts.len() { |
| 525 | false |
| 526 | } else { |
| 527 | let mut eq = true; |
| 528 | for (ac, bc) in a_consts.iter().zip(b_consts.iter()) { |
| 529 | if !vm.bool_eq(ac, bc)? { |
| 530 | eq = false; |
| 531 | break; |
| 532 | } |
| 533 | } |
| 534 | eq |
| 535 | } |
| 536 | }; |
| 537 | Ok(eq.into()) |
| 538 | }) |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | impl Hashable for PyCode { |