Skip to content

Commit a97f5c1

Browse files
committed
feat: Warn about casting an expression to its inferred type
1 parent de8fe30 commit a97f5c1

File tree

5 files changed

+10
-16
lines changed

5 files changed

+10
-16
lines changed

mypy.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ disallow_untyped_defs = True
44
ignore_missing_imports = True
55
no_implicit_optional = True
66
show_error_codes = True
7+
warn_redundant_casts = True

pystac/catalog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ def map_items(
798798
to the item_mapper function.
799799
"""
800800

801-
new_cat = cast(Catalog, self.full_copy())
801+
new_cat = self.full_copy()
802802

803803
def process_catalog(catalog: Catalog) -> None:
804804
for child in catalog.get_children():

pystac/serialization/common_properties.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def merge_common_properties(
7171
(link for link in links if link["rel"] == pystac.RelType.COLLECTION), None
7272
)
7373
if collection_link is not None:
74-
collection_href = cast(Dict[str, Any], collection_link).get("href")
74+
collection_href = collection_link.get("href")
7575
if collection_href is not None:
7676
if json_href is not None:
7777
collection_href = make_absolute_href(collection_href, json_href)

pystac/stac_object.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def add_link(self, link: Link) -> None:
6464
Args:
6565
link : The link to add.
6666
"""
67-
link.set_owner(cast(STACObject, self))
67+
link.set_owner(self)
6868
self.links.append(link)
6969

7070
def add_links(self, links: List[Link]) -> None:
@@ -179,18 +179,14 @@ def set_self_href(self, href: Optional[str]) -> None:
179179
"""
180180
root_link = self.get_root_link()
181181
if root_link is not None and root_link.is_resolved():
182-
cast(pystac.Catalog, root_link.target)._resolved_objects.remove(
183-
cast(STACObject, self)
184-
)
182+
cast(pystac.Catalog, root_link.target)._resolved_objects.remove(self)
185183

186184
self.remove_links(pystac.RelType.SELF)
187185
if href is not None:
188186
self.add_link(Link.self_href(href))
189187

190188
if root_link is not None and root_link.is_resolved():
191-
cast(pystac.Catalog, root_link.target)._resolved_objects.cache(
192-
cast(STACObject, self)
193-
)
189+
cast(pystac.Catalog, root_link.target)._resolved_objects.cache(self)
194190

195191
def get_root(self) -> Optional["Catalog_Type"]:
196192
"""Get the :class:`~pystac.Catalog` or :class:`~pystac.Collection` to

pystac/summaries.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
List,
1414
Optional,
1515
Union,
16-
cast,
1716
TypeVar,
1817
Iterable,
1918
TYPE_CHECKING,
@@ -130,23 +129,23 @@ def _update_with_item(self, summaries: "Summaries", item: "Item_Type") -> None:
130129
and isinstance(v, numbers.Number)
131130
and not isinstance(v, bool)
132131
):
133-
rangesummary: Optional[RangeSummary] = summaries.get_range(k)
132+
rangesummary: Optional[RangeSummary[Any]] = summaries.get_range(k)
134133
if rangesummary is None:
135134
summaries.add(k, RangeSummary(v, v))
136135
else:
137136
rangesummary.update_with_value(v)
138137
elif strategy == SummaryStrategy.ARRAY or (
139138
strategy == SummaryStrategy.DEFAULT and isinstance(v, list)
140139
):
141-
listsummary: list = summaries.get_list(k) or []
140+
listsummary: List[Any] = summaries.get_list(k) or []
142141
if not isinstance(v, list):
143142
v = [v]
144143
for element in v:
145144
if element not in listsummary:
146145
listsummary.append(element)
147146
summaries.add(k, listsummary)
148147
else:
149-
summary: list = summaries.get_list(k) or []
148+
summary: List[Any] = summaries.get_list(k) or []
150149
if v not in summary:
151150
summary.append(v)
152151
summaries.add(k, summary)
@@ -202,9 +201,7 @@ def add(
202201
self.lists[prop_key] = summary
203202
elif isinstance(summary, dict):
204203
if "minimum" in summary:
205-
self.ranges[prop_key] = RangeSummary[Any].from_dict(
206-
cast(Dict[str, Any], summary)
207-
)
204+
self.ranges[prop_key] = RangeSummary[Any].from_dict(summary)
208205
else:
209206
self.schemas[prop_key] = summary
210207
elif isinstance(summary, RangeSummary):

0 commit comments

Comments
 (0)