Repository: sagemath/sage

Issue:
Graph.is_eulerian fails when the graph contains a connected component with non-comparable vertices
### Is there an existing issue for this?

- [X] I have searched the existing issues for a bug report that matches the one I want to file, without success.

### Did you read the documentation and troubleshoot guide?

- [X] I have read the documentation and troubleshoot guide

### Environment

```markdown
- **OS**: Debian 11
- **Sage Version**: 9.8
```


### Steps To Reproduce

```python
G = Graph ([[0, 42, 'John'], [(42, 0)]])
print (G.is_eulerian()) 
H = Graph ([[0, 42, 'John'], [(42, 'John')]])
print (H.is_eulerian())
```

### Expected Behavior

```python
False
False
```

### Actual Behavior

```python
False
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [4], line 1
----> 1 H.is_eulerian()

File ~/src/sage-9.8/src/sage/graphs/generic_graph.py:4123, in GenericGraph.is_eulerian(self, path)
   4120 # unconnected graph can still be Eulerian if all components
   4121 # up to one doesn't contain any edge
   4122 nontrivial_components = 0
-> 4123 for cc in self.connected_components():
   4124     if len(cc) > 1:
   4125         nontrivial_components += 1

File ~/src/sage-9.8/src/sage/graphs/connectivity.pyx:169, in sage.graphs.connectivity.connected_components()
    167 for v in G:
    168     if v not in seen:
--> 169         c = connected_component_containing_vertex(G, v, sort=sort)
    170         seen.update(c)
    171         components.append(c)

File ~/src/sage-9.8/src/sage/graphs/connectivity.pyx:287, in sage.graphs.connectivity.connected_component_containing_vertex()
    285 
    286     if sort:
--> 287         c.sort()
    288     return c
    289 

File ~/src/sage-9.8/src/sage/rings/integer.pyx:916, in sage.rings.integer.Integer.__richcmp__()
    914     c = mpz_cmp_d((<Integer>left).value, d)
    915 else:
--> 916     return coercion_model.richcmp(left, right, op)
    917 
    918 return rich_to_bool_sgn(op, c)

File ~/src/sage-9.8/src/sage/structure/coerce.pyx:2008, in sage.structure.coerce.CoercionModel.richcmp()
   2006     raise bin_op_exception('<=', x, y)
   2007 elif op == Py_GT:
-> 2008     raise bin_op_exception('>', x, y)
   2009 else:
   2010     raise bin_op_exception('>=', x, y)

TypeError: unsupported operand parent(s) for >: 'Integer Ring' and '<class 'str'>'
```

### Additional Information

When a graph contains vertices that are non comparable (like integers and strings) **in the same connected components**, calling `is_eulerian` on this graph raises a `TypeError`.


Discussion:

Resolving patch:
diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py
--- a/src/sage/graphs/generic_graph.py
+++ b/src/sage/graphs/generic_graph.py
@@ -4115,12 +4115,18 @@ def is_eulerian(self, path=False):
 
             sage: g = Graph({0:[], 1:[], 2:[], 3:[]}); g.is_eulerian()
             True
-        """
 
+        Issue :trac:`35168` is fixed::
+
+            sage: Graph([[0, 42, 'John'], [(42, 0)]]).is_eulerian()
+            False
+            sage: Graph([[0, 42, 'John'], [(42, 'John')]]).is_eulerian()
+            False
+        """
         # unconnected graph can still be Eulerian if all components
         # up to one doesn't contain any edge
         nontrivial_components = 0
-        for cc in self.connected_components():
+        for cc in self.connected_components(sort=False):
             if len(cc) > 1:
                 nontrivial_components += 1
             if nontrivial_components > 1:


Test patch: