@@ -65,12 +65,12 @@ class LanguageTool:
6565
6666 :param language: The language to be used by the LanguageTool server. If None, it will try to detect the system language.
6767 :type language: Optional[str]
68- :param motherTongue : The mother tongue of the user.
69- :type motherTongue : Optional[str]
68+ :param mother_tongue : The mother tongue of the user.
69+ :type mother_tongue : Optional[str]
7070 :param remote_server: URL of a remote LanguageTool server. If provided, the local server will not be started.
7171 :type remote_server: Optional[str]
72- :param newSpellings : Custom spellings to be added to the LanguageTool server.
73- :type newSpellings : Optional[List[str]]
72+ :param new_spellings : Custom spellings to be added to the LanguageTool server.
73+ :type new_spellings : Optional[List[str]]
7474 :param new_spellings_persist: Whether the new spellings should persist across sessions.
7575 :type new_spellings_persist: Optional[bool]
7676 :param host: The host address for the LanguageTool server. Defaults to 'localhost'.
@@ -144,9 +144,9 @@ class LanguageTool:
144144 def __init__ (
145145 self ,
146146 language : Optional [str ] = None ,
147- motherTongue : Optional [str ] = None ,
147+ mother_tongue : Optional [str ] = None ,
148148 remote_server : Optional [str ] = None ,
149- newSpellings : Optional [List [str ]] = None ,
149+ new_spellings : Optional [List [str ]] = None ,
150150 new_spellings_persist : bool = True ,
151151 host : Optional [str ] = None ,
152152 config : Optional [Dict [str , Any ]] = None ,
@@ -160,8 +160,7 @@ def __init__(
160160 self ._new_spellings = None
161161 self ._new_spellings_persist = new_spellings_persist
162162 self ._host = host or socket .gethostbyname ("localhost" )
163- self ._available_ports = list (range (8081 , 8999 ))
164- random .shuffle (self ._available_ports )
163+ self ._available_ports = random .sample (range (8081 , 8999 ), (8999 - 8081 ))
165164 self ._port = self ._available_ports .pop ()
166165 self ._server = None
167166
@@ -183,11 +182,11 @@ def __init__(
183182 language = get_locale_language ()
184183 except ValueError :
185184 language = FAILSAFE_LANGUAGE
186- if newSpellings :
187- self ._new_spellings = newSpellings
185+ if new_spellings :
186+ self ._new_spellings = new_spellings
188187 self ._register_spellings ()
189188 self ._language = LanguageTag (language , self ._get_languages ())
190- self ._mother_tongue = motherTongue
189+ self ._mother_tongue = mother_tongue
191190 self .disabled_rules = set ()
192191 self .enabled_rules = set ()
193192 self .disabled_categories = set ()
@@ -255,7 +254,7 @@ def __repr__(self) -> str:
255254 :return: A string that includes the class name, language, and mother tongue.
256255 :rtype: str
257256 """
258- return f"{ self .__class__ .__name__ } (language={ self .language !r} , motherTongue={ self .motherTongue !r} )"
257+ return f"{ self .__class__ .__name__ } (language={ self .language !r} , motherTongue={ self .mother_tongue !r} )"
259258
260259 def close (self ) -> None :
261260 """
@@ -297,7 +296,7 @@ def language(self, language: str) -> None:
297296 self .enabled_rules .clear ()
298297
299298 @property
300- def motherTongue (self ) -> Optional [LanguageTag ]:
299+ def mother_tongue (self ) -> Optional [LanguageTag ]:
301300 """
302301 Retrieve the mother tongue language tag.
303302
@@ -308,16 +307,16 @@ def motherTongue(self) -> Optional[LanguageTag]:
308307 return LanguageTag (self ._mother_tongue , self ._get_languages ())
309308 return None
310309
311- @motherTongue .setter
312- def motherTongue (self , motherTongue : Optional [str ]) -> None :
310+ @mother_tongue .setter
311+ def mother_tongue (self , mother_tongue : Optional [str ]) -> None :
313312 """
314313 Sets the mother tongue for the language tool.
315314
316- :param motherTongue : The mother tongue language tag as a string. If None, the mother tongue is set to None.
317- :type motherTongue : Optional[str]
315+ :param mother_tongue : The mother tongue language tag as a string. If None, the mother tongue is set to None.
316+ :type mother_tongue : Optional[str]
318317 """
319318
320- self ._mother_tongue = motherTongue
319+ self ._mother_tongue = mother_tongue
321320
322321 @property
323322 def _spell_checking_categories (self ) -> Set [str ]:
@@ -367,8 +366,8 @@ def _create_params(self, text: str) -> Dict[str, str]:
367366 - 'level': 'picky' if picky mode is enabled.
368367 """
369368 params = {"language" : str (self .language ), "text" : text }
370- if self .motherTongue is not None :
371- params ["motherTongue" ] = self .motherTongue .tag
369+ if self .mother_tongue is not None :
370+ params ["motherTongue" ] = self .mother_tongue .tag
372371 if self .disabled_rules :
373372 params ["disabledRules" ] = "," .join (self .disabled_rules )
374373 if self .enabled_rules :
@@ -452,9 +451,7 @@ def _register_spellings(self) -> None:
452451 spelling_file_path = self ._get_valid_spelling_file_path ()
453452 logger .debug ("Registering new spellings at %s" , spelling_file_path )
454453 with open (spelling_file_path , "r+" , encoding = "utf-8" ) as spellings_file :
455- existing_spellings = set (
456- line .strip () for line in spellings_file .readlines ()
457- )
454+ existing_spellings = {line .strip () for line in spellings_file .readlines ()}
458455 new_spellings = [
459456 word for word in self ._new_spellings if word not in existing_spellings
460457 ]
0 commit comments