Repository: pyg-team/pytorch_geometric
Pull request #6752 (2023-02-19 15:24:03)

Fix issues in documentation
* Wrong rendering
* Missing doc-strings for `deprecated` classes

codecov[bot]: # [Codecov](https://codecov.io/gh/pyg-team/pytorch_geometric/pull/6752?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) Report
> Merging [#6752](https://codecov.io/gh/pyg-team/pytorch_geometric/pull/6752?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) (d43c565) into [master](https://codecov.io/gh/pyg-team/pytorch_geometric/commit/a75a82a6275a366ed1dab734bb0bdda9591e53c6?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) (a75a82a) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

```diff
@@           Coverage Diff           @@
##           master    #6752   +/-   ##
=======================================
  Coverage   89.21%   89.21%           
=======================================
  Files         425      425           
  Lines       23094    23103    +9     
=======================================
+ Hits        20603    20612    +9     
  Misses       2491     2491           
```


| [Impacted Files](https://codecov.io/gh/pyg-team/pytorch_geometric/pull/6752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) | Coverage Δ | |
|---|---|---|
| [torch\_geometric/utils/negative\_sampling.py](https://codecov.io/gh/pyg-team/pytorch_geometric/pull/6752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team#diff-dG9yY2hfZ2VvbWV0cmljL3V0aWxzL25lZ2F0aXZlX3NhbXBsaW5nLnB5) | `98.54% <ø> (ø)` | |
| [torch\_geometric/deprecation.py](https://codecov.io/gh/pyg-team/pytorch_geometric/pull/6752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team#diff-dG9yY2hfZ2VvbWV0cmljL2RlcHJlY2F0aW9uLnB5) | `100.00% <100.00%> (ø)` | |
| [torch\_geometric/explain/algorithm/pg\_explainer.py](https://codecov.io/gh/pyg-team/pytorch_geometric/pull/6752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team#diff-dG9yY2hfZ2VvbWV0cmljL2V4cGxhaW4vYWxnb3JpdGhtL3BnX2V4cGxhaW5lci5weQ==) | `91.08% <100.00%> (+0.27%)` | :arrow_up: |
| [torch\_geometric/utils/\_\_init\_\_.py](https://codecov.io/gh/pyg-team/pytorch_geometric/pull/6752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team#diff-dG9yY2hfZ2VvbWV0cmljL3V0aWxzL19faW5pdF9fLnB5) | `100.00% <100.00%> (ø)` | |
| [torch\_geometric/utils/embedding.py](https://codecov.io/gh/pyg-team/pytorch_geometric/pull/6752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team#diff-dG9yY2hfZ2VvbWV0cmljL3V0aWxzL2VtYmVkZGluZy5weQ==) | `100.00% <100.00%> (ø)` | |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team)


Patch:
diff --git a/torch_geometric/deprecation.py b/torch_geometric/deprecation.py
index a9edc332d..2edb7716a 100644
--- a/torch_geometric/deprecation.py
+++ b/torch_geometric/deprecation.py
@@ -9,9 +9,10 @@ def deprecated(details: Optional[str] = None, func_name: Optional[str] = None):
         name = func_name or func.__name__
 
         if inspect.isclass(func):
-            func = type(func.__name__, (func, ), {})
-            func.__init__ = deprecated(details, name)(func.__init__)
-            return func
+            cls = type(func.__name__, (func, ), {})
+            cls.__init__ = deprecated(details, name)(func.__init__)
+            cls.__doc__ = func.__doc__
+            return cls
 
         @functools.wraps(func)
         def wrapper(*args, **kwargs):
diff --git a/torch_geometric/explain/algorithm/pg_explainer.py b/torch_geometric/explain/algorithm/pg_explainer.py
index 22d2dcc81..11c672839 100644
--- a/torch_geometric/explain/algorithm/pg_explainer.py
+++ b/torch_geometric/explain/algorithm/pg_explainer.py
@@ -15,7 +15,7 @@ from torch_geometric.explain.config import (
 )
 from torch_geometric.nn import Linear
 from torch_geometric.nn.inits import reset
-from torch_geometric.utils import get_message_passing_embeddings
+from torch_geometric.utils import get_embeddings
 
 
 class PGExplainer(ExplainerAlgorithm):
@@ -120,7 +120,7 @@ class PGExplainer(ExplainerAlgorithm):
                 raise ValueError(f"Only scalars are supported for the 'index' "
                                  f"argument in '{self.__class__.__name__}'")
 
-        z = get_message_passing_embeddings(model, x, edge_index, **kwargs)[-1]
+        z = get_embeddings(model, x, edge_index, **kwargs)[-1]
 
         self.optimizer.zero_grad()
         temperature = self._get_temperature(epoch)
@@ -185,7 +185,7 @@ class PGExplainer(ExplainerAlgorithm):
             _, hard_edge_mask = self._get_hard_masks(model, index, edge_index,
                                                      num_nodes=x.size(0))
 
-        z = get_message_passing_embeddings(model, x, edge_index, **kwargs)[-1]
+        z = get_embeddings(model, x, edge_index, **kwargs)[-1]
 
         inputs = self._get_inputs(z, edge_index, index)
         logits = self.mlp(inputs).view(-1)
diff --git a/torch_geometric/utils/__init__.py b/torch_geometric/utils/__init__.py
index 6fc63100b..0e8a38f83 100644
--- a/torch_geometric/utils/__init__.py
+++ b/torch_geometric/utils/__init__.py
@@ -1,3 +1,5 @@
+import copy
+
 from .scatter import scatter
 from .segment import segment
 from .sort import index_sort
@@ -41,7 +43,7 @@ from .negative_sampling import (negative_sampling, batched_negative_sampling,
                                 structured_negative_sampling,
                                 structured_negative_sampling_feasible)
 from .tree_decomposition import tree_decomposition
-from .embedding import get_message_passing_embeddings
+from .embedding import get_embeddings
 from .train_test_split_edges import train_test_split_edges
 
 __all__ = [
@@ -114,8 +116,11 @@ __all__ = [
     'structured_negative_sampling',
     'structured_negative_sampling_feasible',
     'tree_decomposition',
-    'get_message_passing_embeddings',
+    'get_embeddings',
     'train_test_split_edges',
 ]
 
-classes = __all__
+# `structured_negative_sampling_feasible` is a long name and thus destroys the
+# documentation rendering. We remove it for now from the documentation:
+classes = copy.copy(__all__)
+classes.remove('structured_negative_sampling_feasible')
diff --git a/torch_geometric/utils/embedding.py b/torch_geometric/utils/embedding.py
index a1222cdba..affccba04 100644
--- a/torch_geometric/utils/embedding.py
+++ b/torch_geometric/utils/embedding.py
@@ -5,7 +5,7 @@ import torch
 from torch import Tensor
 
 
-def get_message_passing_embeddings(
+def get_embeddings(
     model: torch.nn.Module,
     *args,
     **kwargs,
diff --git a/torch_geometric/utils/negative_sampling.py b/torch_geometric/utils/negative_sampling.py
index 78fe77acb..f56c0a5fc 100644
--- a/torch_geometric/utils/negative_sampling.py
+++ b/torch_geometric/utils/negative_sampling.py
@@ -250,12 +250,14 @@ def structured_negative_sampling(edge_index, num_nodes: Optional[int] = None,
 
 
 def structured_negative_sampling_feasible(
-        edge_index: Tensor, num_nodes: Optional[int] = None,
-        contains_neg_self_loops: bool = True) -> bool:
+    edge_index: Tensor,
+    num_nodes: Optional[int] = None,
+    contains_neg_self_loops: bool = True,
+) -> bool:
     r"""Returns :obj:`True` if
     :meth:`~torch_geometric.utils.structured_negative_sampling` is feasible
     on the graph given by :obj:`edge_index`.
-    :obj:`~torch_geometric.utils.structured_negative_sampling` is infeasible
+    :meth:`~torch_geometric.utils.structured_negative_sampling` is infeasible
     if atleast one node is connected to all other nodes.
 
     Args:


Test patch:
diff --git a/test/utils/test_embedding.py b/test/utils/test_embedding.py
index 060e755ff..60cb058e9 100644
--- a/test/utils/test_embedding.py
+++ b/test/utils/test_embedding.py
@@ -2,7 +2,7 @@ import pytest
 import torch
 
 from torch_geometric.nn import GCNConv, Linear
-from torch_geometric.utils import get_message_passing_embeddings
+from torch_geometric.utils import get_embeddings
 
 
 class GNN(torch.nn.Module):
@@ -17,18 +17,18 @@ class GNN(torch.nn.Module):
         return [x1, x2]
 
 
-def test_get_message_passing_embeddings():
+def test_get_embeddings():
     x = torch.randn(6, 5)
     edge_index = torch.tensor([[0, 1, 2, 3, 4], [1, 2, 3, 4, 5]])
 
     with pytest.warns(UserWarning, match="any 'MessagePassing' layers"):
-        intermediate_outs = get_message_passing_embeddings(Linear(5, 5), x)
+        intermediate_outs = get_embeddings(Linear(5, 5), x)
     assert len(intermediate_outs) == 0
 
     model = GNN()
     expected_embeddings = model(x, edge_index)
 
-    embeddings = get_message_passing_embeddings(model, x, edge_index)
+    embeddings = get_embeddings(model, x, edge_index)
     assert len(embeddings) == 2
     for expected, out in zip(expected_embeddings, embeddings):
         assert torch.allclose(expected, out)