#15278: Hash and equality for graphs
-------------------------------------+-------------------------------------
       Reporter:  SimonKing          |        Owner:
           Type:  defect             |       Status:  needs_info
       Priority:  major              |    Milestone:  sage-6.1
      Component:  graph theory       |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Simon King         |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/SimonKing/ticket/15278           |  2fc8a772ee12fce7ac6abc4ecf9916f4746f5ee2
   Dependencies:  #12601, #15491     |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by SimonKing):

 Replying to [comment:47 ncohen]:
 > > Problem: If I am not mistaken, people currently ''do'' mess with the
 attribute `._immutable`, if I am not mistaken.
 >
 > Yes yes indeed, that's what Nicolas told me they did at the moment, and
 that's what Python uses too know whether it should consider the object as
 mutable or not. I just wondered if it checked whether the variable
 existed, or whether the variable was set to True too.

 The usage is `if getattr(self,'_immutable',False/True): raise
 TypeError("...")` (false or true depending on whether we want to allow
 something for all graphs except those that are known to be mutable, or
 allow something for all graphs except those that are known to be
 immutable).

 > > Would it be feasible to try to remove the `._immutable` attribute (and
 testing the type of the backend instead), see how much fails, and fix the
 failing code by using "proper" immutable graphs?
 >
 > Hmmmm, I thought that Python really needed this `_immutable` variable
 somewhere `O_o`

 I've never heard before that Python uses it.

 > > Would a flag in the "copy" function be supported by Python?
 >
 > Well not in `.__copy__` but in `.copy()` no problem I guess.

 Now we talk about three things. I was talking about Python's (or Sage's?)
 `copy()` function, which dispatches to `__copy__` or to pickling,
 depending on what's available. You talk about the `.__copy__()` method,
 which exists for graphs, and the `.copy()` method, which is set to
 `__copy__` for graphs.

 The `copy()` ''function'' does not use any argument except the object that
 is being copied. For that reason, I think the `__copy__` method ''should''
 not accept any arguments except `self`. But currently, the `.__copy__()`
 method of graphs uses a plethora of optional arguments.

 Instead, I suggest that one should introduce a separate `.copy()` method:
 Here, it is no problem to add arguments. In particular, you can use such
 method to create a mutable copy resp. an immutable copy of an immutable
 resp. a mutable (di)graph. And it would be available in the docs (unlike
 `.__copy__()`).

 On the other hand (thinking after writing, as usual...): The optional
 arguments of `__copy__` are not used, but when one defines `copy=__copy__`
 then the method and its documentation do appear in the docs and can be
 used by people. Hm. In the end, it might be better to keep it.

 But one question on copying needs to be addressed: I think in some places
 in Sage, `copy(X)` returns `X` if `X` is immutable, but in other places in
 Sage, `copy(X)` always returns a ''mutable'' copy of `X`, regardless
 whether `X` is mutable or not. What would you prefer for graphs?

 In any case, I should add a test showing what happens with copies of
 immutable graphs.

 > I usually settle this by setting the keywords to "None" by default,
 instead of True/False. Then if the user manually sets two keywords to
 contradicting values, either ignore one of the two or scream, as usual.
 I'll do that in another patch when this one will be reviewed, it will be
 an easier syntax.

 Do I understand correctly: You say I shouldn't try to add the "nicer"
 syntax now, since you would take care of it in a review patch/other
 ticket?

--
Ticket URL: <http://trac.sagemath.org/ticket/15278#comment:50>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to