New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
General code cleanup: avoid code like x.__eq__(y) #19597
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
Commit: |
comment:9
Could you comment more on this two changes diff --git a/src/sage/coding/codecan/codecan.pyx b/src/sage/coding/codecan/codecan.pyx
index 4d092d1..7b0bec3 100644
--- a/src/sage/coding/codecan/codecan.pyx
+++ b/src/sage/coding/codecan/codecan.pyx
@@ -803,7 +803,6 @@ cdef class PartitionRefinementLinearCode(PartitionRefinement_generic):
self._hyp_refine_vals_scratch = <long *> sage_malloc(
self._hyp_part.degree * sizeof(long))
if self._hyp_refine_vals_scratch is NULL:
- self.__dealloc__()
raise MemoryError('allocating PartitionRefinementLinearCode')
self._hyp_refine_vals = _BestValStore(self._hyp_part.degree) diff --git a/src/sage/combinat/crystals/tensor_product.py b/src/sage/combinat/crystals/tensor_product.py
index 9596832..f3d277b 100644
--- a/src/sage/combinat/crystals/tensor_product.py
+++ b/src/sage/combinat/crystals/tensor_product.py
@@ -199,9 +199,7 @@ class ImmutableListWithParent(CombinatorialElement):
sage: m <= n
True
"""
- if self == other:
- return True
- return self.__lt__(other)
+ return self == other or self.__lt__(other)
def __gt__(self, other):
@@ -237,9 +235,7 @@ class ImmutableListWithParent(CombinatorialElement):
sage: m >= n
False
"""
- if self == other:
- return True
- return self.__gt__(other)
+ return self == other or self.__gt__(other)
def sibling(self, l): More comments:
|
comment:10
About In |
comment:11
Replying to @videlec:
That's true in general, however: there is no That's probably also the reason the old code was written like |
comment:12
Replying to @jdemeyer:
Let me also mention that this is the only place in Sage where a comparison method In And there are several other places where a |
comment:13
Replying to @videlec:
It's apparently intentional. The doc says that it's more efficient to compute |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Reviewer: Vincent Delecroix |
Changed branch from u/jdemeyer/general_code_cleanup__avoid_x___eq___y_ to |
Changed commit from |
comment:17
that was a bit too quick, and broke some optional doctests, see |
Replace code of the form
by
because the latter are more efficient.
The obvious exceptions are
super()
calls andClass.__method__(...)
calls.In a few cases, we reorganize the code to avoid special functions/methods altogether:
__repr__()
, we instead change%s
to%r
for%
-formatting and{}
to{!r}
for.format()
.__iter__()
can be changed to a simple list comprehension.x.__eq__(y)
andx == y
and in certain technical cases they do matter.Component: misc
Author: Jeroen Demeyer
Branch:
4a950ac
Reviewer: Vincent Delecroix
Issue created by migration from https://trac.sagemath.org/ticket/19597
The text was updated successfully, but these errors were encountered: