Repository: stravalib/stravalib
Pull request #514 (2024-06-01 03:38:49)

Fix: remove deprecated client methods
closes #513 



## Description

Tiny pr to remove deprecated methods. 

## Type of change

Select the statement best describes this pull request.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
- [ ] This is a documentation update
- [ ] This is a infrastructure update (docs, ci, etc)
- [x] Other (please describe)

## Does your PR include tests

If you are fixing a bug or adding a feature, we appreciate (but do not require)
tests to support whatever fix of feature you're implementing.

- [ ] Yes
- [ ] No, i'd like some help with tests
- [x] This change doesn't require tests

## Did you include your contribution to the change log?

- [ ] Yes, `changelog.md` is up-to-date.

There are no tests associated with these endpoints / methods that i can see. 



Patch:
diff --git a/src/stravalib/client.py b/src/stravalib/client.py
index 72dbd3c..71b2182 100644
--- a/src/stravalib/client.py
+++ b/src/stravalib/client.py
@@ -651,26 +651,6 @@ class Client:
         )
         return model.Activity.model_validate({**raw, **{"bound_client": self}})
 
-    # TODO: REMOVE from API altogether given deprecation of end point
-    def get_friend_activities(self, limit: int | None = None) -> NoReturn:
-        """DEPRECATED This endpoint was removed by Strava in Jan 2018.
-
-        Parameters
-        ----------
-        limit : int
-            Maximum number of activities to return. (default unlimited)
-
-        Returns
-        -------
-        class:`BatchedResultsIterator`
-            An iterator of :class:`stravalib.model.Activity` objects.
-
-        """
-        raise NotImplementedError(
-            "The /activities/following endpoint was removed by Strava.  "
-            "See https://developers.strava.com/docs/january-2018-update/"
-        )
-
     def _validate_activity_type(
         self,
         params: dict[str, Any],
@@ -1200,30 +1180,6 @@ class Client:
             result_fetcher=result_fetcher,
         )
 
-    # TODO remove this method given deprecation of end point
-    def get_related_activities(
-        self, activity_id: int, limit: int | None = None
-    ) -> NoReturn:
-        """Deprecated. This endpoint was removed by strava in Jan 2018.
-
-        Parameters
-        ----------
-        activity_id : int
-            The activity for which to fetch related activities.
-        limit : int, default=None
-             Rate limit value for getting activities
-
-        Returns
-        -------
-        class:`BatchedResultsIterator`
-            An iterator of :class:`stravalib.model.Activity` objects.
-
-        """
-        raise NotImplementedError(
-            "The /activities/{id}/related endpoint was removed by Strava.  "
-            "See https://developers.strava.com/docs/january-2018-update/"
-        )
-
     def get_gear(self, gear_id: str) -> model.Gear:
         """Get details for an item of gear.
 
@@ -1289,7 +1245,7 @@ class Client:
 
     def get_starred_segments(
         self, limit: int | None = None
-    ) -> BatchedResultsIterator[model.Segment]:
+    ) -> BatchedResultsIterator[model.SummarySegment]:
         """Returns a summary representation of the segments starred by the
          authenticated user. Pagination is supported.
 
@@ -1303,7 +1259,7 @@ class Client:
         Returns
         -------
         class:`BatchedResultsIterator`
-            An iterator of :class:`stravalib.model.Segment` starred by authenticated user.
+            An iterator of :class:`stravalib.model.SummarySegment` starred by authenticated user.
 
         """
 
@@ -1316,7 +1272,7 @@ class Client:
         )
 
         return BatchedResultsIterator(
-            entity=model.Segment,
+            entity=model.SummarySegment,
             bind_client=self,
             result_fetcher=result_fetcher,
             limit=limit,
diff --git a/src/stravalib/model.py b/src/stravalib/model.py
index 9891b79..e9c8cff 100644
--- a/src/stravalib/model.py
+++ b/src/stravalib/model.py
@@ -39,7 +39,6 @@ from stravalib.strava_model import (
     Comment,
     DetailedClub,
     DetailedGear,
-    DetailedSegment,
     DetailedSegmentEffort,
     ExplorerSegment,
     Lap,
@@ -743,22 +742,27 @@ class AthletePrEffort(
         return self.pr_elapsed_time
 
 
-class Segment(
-    DetailedSegment,
-    BoundClientEntity,
-):
-    """
-    Represents a single Strava segment.
-    """
-
+class SummarySegment(strava_model.SummarySegment, BoundClientEntity):
     # Field overrides from superclass for type extensions:
     start_latlng: Optional[LatLon] = None
     end_latlng: Optional[LatLon] = None
-    map: Optional[Map] = None
     athlete_segment_stats: Optional[AthleteSegmentStats] = None
     athlete_pr_effort: Optional[AthletePrEffort] = None
     activity_type: Optional[RelaxedActivityType] = None  # type: ignore[assignment]
 
+    _latlng_check = field_validator(
+        "start_latlng", "end_latlng", mode="before"
+    )(check_valid_location)
+
+
+class Segment(SummarySegment, strava_model.DetailedSegment):
+    """
+    Represents a single Strava segment.
+    """
+
+    # Field overrides from superclass for type extensions:
+    map: Optional[Map] = None
+
     # Undocumented attributes:
     start_latitude: Optional[float] = None
     end_latitude: Optional[float] = None
@@ -769,10 +773,6 @@ class Segment(
     starred_date: Optional[datetime] = None
     elevation_profile: Optional[str] = None
 
-    _latlng_check = field_validator(
-        "start_latlng", "end_latlng", mode="before"
-    )(check_valid_location)
-
 
 class SegmentEffortAchievement(BaseModel):
     """
@@ -810,7 +810,7 @@ class BaseEffort(
     """
 
     # Field overrides from superclass for type extensions:
-    segment: Optional[Segment] = None
+    segment: Optional[SummarySegment] = None
     activity: Optional[Activity] = None
     athlete: Optional[Athlete] = None
 
@@ -995,7 +995,7 @@ class Route(
     # Superclass field overrides for using extended types
     athlete: Optional[SummaryAthlete] = None
     map: Optional[Map] = None
-    segments: Optional[list[Segment]]  # type: ignore[assignment]
+    segments: Optional[list[SummarySegment]]  # type: ignore[assignment]
 
 
 class Subscription(BaseModel):


Test patch:
diff --git a/src/stravalib/tests/integration/test_client.py b/src/stravalib/tests/integration/test_client.py
index 6d8d1d8..c2ee3b0 100644
--- a/src/stravalib/tests/integration/test_client.py
+++ b/src/stravalib/tests/integration/test_client.py
@@ -9,7 +9,7 @@ from responses import matchers
 
 from stravalib.client import ActivityUploader
 from stravalib.exc import AccessUnauthorized, ActivityPhotoUploadFailed
-from stravalib.model import Athlete, SummaryAthlete
+from stravalib.model import Athlete, SummaryAthlete, SummarySegment
 from stravalib.strava_model import SummaryActivity
 from stravalib.tests import RESOURCES_DIR
 from stravalib.unithelper import miles
@@ -719,10 +719,11 @@ def test_get_starred_segments(
         n_results=n_raw_results,
     )
     kwargs = {"limit": limit} if limit is not None else {}
-    activity_list = list(client.get_starred_segments(**kwargs))
-    assert len(activity_list) == expected_n_segments
+    segment_list = list(client.get_starred_segments(**kwargs))
+    assert len(segment_list) == expected_n_segments
     if expected_n_segments > 0:
-        assert activity_list[0].name == "test_segment"
+        assert isinstance(segment_list[0], SummarySegment)
+        assert segment_list[0].name == "test_segment"
 
 
 def test_get_club(mock_strava_api, client):