Skip to content

Commit

Permalink
ci: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohan Bansal committed Feb 11, 2025
1 parent 5165808 commit dc782d3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
72 changes: 42 additions & 30 deletions shipstation/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def list_tags(self) -> list[str | ShipStationOrderTag]:
return [ShipStationOrderTag().json(tag) for tag in tags.json(parse_float=Decimal)]

# CARRIERS
def get_carrier(self, carrier_code: str) -> ShipStationCarrier:
def get_carrier(self, carrier_code: str) -> str | ShipStationCarrier:
"""
Retrieves the shipping carrier account details for the specified carrierCode.
Use this method to determine a carrier's account balance.
Expand Down Expand Up @@ -108,10 +108,12 @@ def list_customers(self, parameters: dict[str, Any] | None = None) -> Page:
parameters = {}
valid_parameters = self._validate_parameters(parameters, CUSTOMER_LIST_PARAMETERS)
return Page(
type=ShipStationCustomer,
key="customers",
params=valid_parameters,
call=(self.get, {"endpoint": "/customers"}),
**{
"type": ShipStationCustomer,
"key": "customers",
"params": valid_parameters,
"call": (self.get, {"endpoint": "/customers"}),
}
)

# FULFILLMENTS
Expand All @@ -129,10 +131,12 @@ def list_fulfillments(self, parameters: dict[str, Any] | None = None) -> Page:
parameters = {}
valid_parameters = self._validate_parameters(parameters, FULFILLMENT_LIST_PARAMETERS)
return Page(
type=ShipStationFulfillment,
key="fulfillments",
params=valid_parameters,
call=(self.get, {"endpoint": "/fulfillments"}),
**{
"type": ShipStationFulfillment,
"key": "fulfillments",
"params": valid_parameters,
"call": (self.get, {"endpoint": "/fulfillments"}),
}
)

# ORDERS
Expand Down Expand Up @@ -192,7 +196,7 @@ def create_label_for_order(
return r.json()
new_data = self.convert_camel_case(r.json())
if pdf:
return BytesIO(base64.b64decode(new_data["label_data"]))
return BytesIO(base64.b64decode(new_data["label_data"])) # type: ignore
if isinstance(new_data, dict):
for key, value in new_data.items():
if value:
Expand Down Expand Up @@ -229,7 +233,7 @@ def create_orders(self, orders: list[ShipStationOrder]) -> list[str | ShipStatio
responses.append(ShipStationOrder().json(r.json(parse_float=Decimal)))
return responses

def create_order(self, order: ShipStationOrder) -> ShipStationOrder:
def create_order(self, order: ShipStationOrder) -> str | ShipStationOrder:
"""
You can use this method to create a new order or update an existing order.
If the `orderKey` is specified, ShipStation will attempt to locate the order with the
Expand Down Expand Up @@ -315,10 +319,12 @@ def list_orders_by_tag(
parameters = {}
valid_parameters = self._validate_parameters(parameters, ORDER_LIST_BY_TAG_PARAMETERS)
return Page(
type=ShipStationOrder,
key="orders",
params=valid_parameters,
call=(self.get, {"endpoint": "/orders/listbytag"}),
**{
"type": ShipStationOrder,
"key": "orders",
"params": valid_parameters,
"call": (self.get, {"endpoint": "/orders/listbytag"}),
}
)

def list_orders(self, parameters: dict[str, Any] | None = None) -> Page:
Expand All @@ -336,10 +342,12 @@ def list_orders(self, parameters: dict[str, Any] | None = None) -> Page:
self.require_type(parameters, dict)
valid_parameters = self._validate_parameters(parameters, ORDER_LIST_PARAMETERS)
return Page(
type=ShipStationOrder,
key="orders",
params=valid_parameters,
call=(self.get, {"endpoint": "/orders"}),
**{
"type": ShipStationOrder,
"key": "orders",
"params": valid_parameters,
"call": (self.get, {"endpoint": "/orders"}),
}
)

def mark_order_as_shipped(
Expand Down Expand Up @@ -453,10 +461,12 @@ def list_products(self, parameters: dict[str, Any] | None = None) -> Page:
parameters = {}
valid_parameters = self._validate_parameters(parameters, PRODUCT_LIST_PARAMETERS)
return Page(
type=ShipStationItem,
key="products",
params=valid_parameters,
call=(self.get, {"endpoint": "/products"}),
**{
"type": ShipStationItem,
"key": "products",
"params": valid_parameters,
"call": (self.get, {"endpoint": "/products"}),
}
)

def update_product(self, product: ShipStationItem) -> Any:
Expand Down Expand Up @@ -519,10 +529,12 @@ def list_shipments(self, parameters: dict[str, Any] | None = None) -> Page:
parameters = {}
valid_parameters = self._validate_parameters(parameters, SHIPMENT_LIST_PARAMETERS)
return Page(
type=ShipStationOrder,
key="shipments",
params=valid_parameters,
call=(self.get, {"endpoint": "/shipments"}),
**{
"type": ShipStationOrder,
"key": "shipments",
"params": valid_parameters,
"call": (self.get, {"endpoint": "/shipments"}),
}
)

def void_label(self, shipment_id: str) -> Any:
Expand Down Expand Up @@ -593,7 +605,7 @@ def list_stores(
parameters["showInactive"] = show_inactive
if marketplace_id:
self.require_type(marketplace_id, int)
parameters["marketplaceId"] = marketplace_id
parameters["marketplaceId"] = marketplace_id # type: ignore
stores = self.get(endpoint="/stores", payload=parameters)
return [ShipStationStore().json(s) for s in stores.json(parse_float=Decimal) if s]

Expand All @@ -610,7 +622,7 @@ def update_store(self, parameters: dict[str, Any]) -> str | ShipStationStore:
for m in UPDATE_STORE_OPTIONS:
self.require_attribute(m)
self.require_type(parameters.get("status_mappings"), list)
for mapping in parameters.get("status_mappings"):
for mapping in parameters.get("status_mappings"): # type: ignore
self.require_type(mapping, ShipStationStatusMapping)
self.require_membership(mapping["orderStatus"], ORDER_STATUS_VALUES)
store = self.put(endpoint="/stores/storeId", data=parameters)
Expand Down Expand Up @@ -722,7 +734,7 @@ def list_webhooks(self) -> list[str | ShipStationWebhook]:

r = self.get(endpoint="/webhooks")
webhooks = r.json(parse_float=Decimal).get("webhooks") if r.status_code == 200 else None
return [ShipStationWebhook().json(w) for w in webhooks if w]
return [ShipStationWebhook().json(w) for w in webhooks if w] if webhooks else []

# return same webhook object with new webhook id
def subscribe_to_webhook(self, webhook: ShipStationWebhook) -> ShipStationWebhook:
Expand Down
6 changes: 3 additions & 3 deletions shipstation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections.abc import Iterable
from datetime import date, datetime
from decimal import Decimal
from typing import Any, Union
from typing import Any, Self, Union
from uuid import UUID

from cattrs import Converter
Expand Down Expand Up @@ -74,14 +74,14 @@ def require_membership(self, value: Any, other: Any) -> None:
raise AttributeError(f"'{value}' is not one of {other}")

def _validate_parameters(
self, parameters: dict[str, Any], valid_parameters: tuple[str]
self, parameters: dict[str, Any], valid_parameters: tuple[str, ...]
) -> dict[str, Any]:
invalid_keys = set(parameters.keys()).difference(valid_parameters)
if invalid_keys:
raise AttributeError("Invalid order list parameters: {}".format(", ".join(invalid_keys)))
return {self.to_camel_case(key): value for key, value in parameters.items()}

def json(self, json_str: None | str | dict[str, Any] = None) -> Union[str, "ShipStationBase"]:
def json(self, json_str: None | str | dict[str, Any] = None) -> str | Self:
if not json_str:
return json.dumps(self.convert_snake_case(self._unstructure()))
if isinstance(json_str, dict):
Expand Down
2 changes: 1 addition & 1 deletion shipstation/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Page:
key: str
type: type
call: tuple[Callable, dict[str, Any]] | None
call: tuple[Callable, dict[str, Any]]
results: list[ShipStationBase] = []
params: dict[str, Any] | None = None
page: int = 0
Expand Down

0 comments on commit dc782d3

Please sign in to comment.