Skip to content

Commit

Permalink
Fixes Pylint error codes W0622, W1514
Browse files Browse the repository at this point in the history
W0622: Redefining built-in 'type'
W1514: Unspecified encoding in `open`
  • Loading branch information
cr2007 committed Jun 4, 2024
1 parent ae9bd26 commit 2722090
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cambai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ def create_api_endpoint(self, endpoint: str) -> str:
return self.CAMB_URL + endpoint


def get_languages(self, type: Literal["source", "target"],
def get_languages(self, language_type: Literal["source", "target"],
write_to_file: bool = False) -> list[LanguageOptionsDict]:
"""
Retrieves a list of languages from the API endpoint based on the type specified.
Args:
- type (Literal["source", "target"]): Specifies the type of languages to retrieve.
- language_type (Literal["source", "target"]): Specifies the type of languages to retrieve.
Can be either "source" for source languages or "target" for target languages.
- get_languages (bool, optional): If True, retrieves the languages. Defaults to False.
Expand All @@ -165,7 +165,7 @@ def get_languages(self, type: Literal["source", "target"],
HTTPError: If the GET request to the API endpoint fails.
"""
# Construct the API endpoint URL
url: str = self.create_api_endpoint(f"{type}_languages")
url: str = self.create_api_endpoint(f"{language_type}_languages")

# Send a GET request to the API endpoint
response: requests.Response = self.session.get(url)
Expand All @@ -174,9 +174,9 @@ def get_languages(self, type: Literal["source", "target"],
response.raise_for_status()

if write_to_file:
with open(f"{type}_languages.json", "w") as f:
with open(f"{language_type}_languages.json", "w", encoding="utf-8") as f:
json.dump(response.json(), f, indent=4)
print(f"{type} languages written to {type}_languages.json")
print(f"{language_type} languages written to {language_type}_languages.json")

# Return the response data as a list of language dictionaries
return response.json()
Expand Down Expand Up @@ -210,7 +210,7 @@ def get_all_voices(self, write_to_file: bool = False) -> list[Optional[VoicesLis
# If write_to_file is True, write the response to a JSON file
if write_to_file:
# Open the file in write mode
with open("voices.json", "w") as f:
with open("voices.json", "w", encoding="utf-8") as f:
# Dump the JSON response into the file with indentation for readability
json.dump(response.json(), f, indent=4)
print("Voices written to voices.json")
Expand Down

0 comments on commit 2722090

Please sign in to comment.