-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Error when creating class with unknown keyword argument (#209)
- Loading branch information
1 parent
a2b6913
commit c5bc317
Showing
5 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from anywidget import AnyWidget | ||
from ipywidgets import Widget | ||
|
||
|
||
class BaseWidget(Widget): | ||
def __init__(self, **kwargs): | ||
# Raise error on unknown keyword name | ||
layer_trait_names = self.class_own_traits().keys() | ||
for provided_trait_name in kwargs.keys(): | ||
if provided_trait_name not in layer_trait_names: | ||
raise TypeError(f"unexpected keyword argument '{provided_trait_name}'") | ||
|
||
super().__init__(**kwargs) | ||
|
||
|
||
class BaseAnyWidget(AnyWidget): | ||
def __init__(self, **kwargs): | ||
# Raise error on unknown keyword name | ||
layer_trait_names = self.class_own_traits().keys() | ||
for provided_trait_name in kwargs.keys(): | ||
if provided_trait_name not in layer_trait_names: | ||
raise TypeError(f"unexpected keyword argument '{provided_trait_name}'") | ||
|
||
super().__init__(**kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import geopandas as gpd | ||
import pytest | ||
import shapely | ||
|
||
from lonboard import Map, ScatterplotLayer | ||
|
||
|
||
def test_map_fails_with_unexpected_argument(): | ||
points = shapely.points([1, 2], [3, 4]) | ||
gdf = gpd.GeoDataFrame(geometry=points) | ||
|
||
layer = ScatterplotLayer.from_geopandas(gdf) | ||
|
||
with pytest.raises(TypeError, match="unexpected keyword argument"): | ||
Map(layers=[layer], unknown_keyword="foo") |