Pyzotero: a Python client for the Zotero API pyzotero.readthedocs.io
zotero

Fix typing errors found by ty

+27 -16
+3
pyproject.toml
··· 116 116 117 117 # Like Black, indent with spaces, rather than tabs. 118 118 indent-style = "space" 119 + 120 + [tool.ty.rules] 121 + possibly-missing-attribute = "ignore"
+24 -16
src/pyzotero/zotero.py
··· 698 698 f"/{self.library_type}/{self.library_id}/items/{itemkey}/fulltext", 699 699 ), 700 700 headers=headers, 701 - data=json.dumps(payload), 701 + json=payload, 702 702 ) 703 703 704 704 def new_fulltext(self, since): ··· 926 926 927 927 def makeiter(self, func): 928 928 """Return a generator of func's results""" 929 + if self.links is None or "self" not in self.links: 930 + msg = "makeiter() requires a previous API call with pagination links" 931 + raise RuntimeError(msg) 929 932 # reset the link. This results in an extra API call, yes 930 933 self.links["next"] = self.links["self"] 931 934 return self.iterfollow() ··· 1082 1085 f"/{self.library_type}/{self.library_id}/searches", 1083 1086 ), 1084 1087 headers=headers, 1085 - data=json.dumps(payload), 1088 + json=payload, 1086 1089 ) 1087 1090 self.request = req 1088 1091 try: ··· 1306 1309 "If-Unmodified-Since-Version": req.headers["last-modified-version"], 1307 1310 } 1308 1311 for value in resp["success"].values(): 1309 - payload = json.dumps({"parentItem": parentid}) 1312 + payload = {"parentItem": parentid} 1310 1313 self._check_backoff() 1311 1314 presp = self.client.patch( 1312 1315 url=build_url( 1313 1316 self.endpoint, 1314 1317 f"/{self.library_type}/{self.library_id}/items/{value}", 1315 1318 ), 1316 - data=payload, 1319 + json=payload, 1317 1320 headers=dict(uheaders), 1318 1321 ) 1319 1322 self.request = presp ··· 1452 1455 self.endpoint, 1453 1456 f"/{self.library_type}/{self.library_id}/items/", 1454 1457 ), 1455 - data=json.dumps(chunk), 1458 + json=chunk, 1456 1459 ) 1457 1460 self.request = req 1458 1461 try: ··· 1478 1481 self.endpoint, 1479 1482 f"/{self.library_type}/{self.library_id}/collections/", 1480 1483 ), 1481 - data=json.dumps(chunk), 1484 + json=chunk, 1482 1485 ) 1483 1486 self.request = req 1484 1487 try: ··· 1506 1509 self.endpoint, 1507 1510 f"/{self.library_type}/{self.library_id}/items/{ident}", 1508 1511 ), 1509 - data=json.dumps({"collections": modified_collections}), 1512 + json={"collections": modified_collections}, 1510 1513 headers=headers, 1511 1514 ) 1512 1515 ··· 1528 1531 self.endpoint, 1529 1532 f"/{self.library_type}/{self.library_id}/items/{ident}", 1530 1533 ), 1531 - data=json.dumps({"collections": modified_collections}), 1534 + json={"collections": modified_collections}, 1532 1535 headers=headers, 1533 1536 ) 1534 1537 ··· 1646 1649 delay = req.headers.get("backoff") or req.headers.get("retry-after") 1647 1650 if not delay: 1648 1651 msg = "You are being rate-limited and no backoff or retry duration has been received from the server. Try again later" 1649 - raise ze.TooManyRetriesError( 1650 - msg, 1651 - ) 1652 + raise ze.TooManyRetriesError(msg) 1652 1653 zot._set_backoff(delay) 1653 1654 elif not exc: 1654 - raise error_codes.get(req.status_code)(err_msg(req)) 1655 + raise error_codes[req.status_code](err_msg(req)) 1655 1656 else: 1656 - raise error_codes.get(req.status_code)(err_msg(req)) from exc 1657 + raise error_codes[req.status_code]( 1658 + err_msg(req) 1659 + ) from exc # ← Direct indexing 1657 1660 elif not exc: 1658 1661 raise ze.HTTPError(err_msg(req)) 1659 1662 else: ··· 1816 1819 permitted_operators = self.conditions_operators.get( 1817 1820 condition.get("condition"), 1818 1821 ) 1822 + if permitted_operators is None: 1823 + msg = f"Unknown condition: {condition.get('condition')}" 1824 + raise ze.ParamNotPassedError(msg) 1819 1825 # transform these into values 1820 1826 permitted_operators_list = { 1821 - self.operators.get(op) for op in permitted_operators 1827 + op_value 1828 + for op in permitted_operators 1829 + if (op_value := self.operators.get(op)) is not None 1822 1830 } 1823 1831 if condition.get("operator") not in permitted_operators_list: 1824 1832 msg = f"You may not use the '{condition.get('operator')}' operator when selecting the '{condition.get('condition')}' condition. \nAllowed operators: {', '.join(list(permitted_operators_list))}" ··· 1979 1987 files=upload_pairs, 1980 1988 headers={"User-Agent": f"Pyzotero/{pz.__version__}"}, 1981 1989 ) 1982 - except httpx.ConnectionError: 1990 + except httpx.ConnectError: 1983 1991 msg = "ConnectionError" 1984 1992 raise ze.UploadError(msg) from None 1985 1993 try: ··· 2016 2024 "retry-after", 2017 2025 ) 2018 2026 if backoff: 2019 - self._set_backoff(backoff) 2027 + self.zinstance._set_backoff(backoff) 2020 2028 2021 2029 def upload(self): 2022 2030 """File upload functionality