Skip to content

Commit fdd1a1f

Browse files
docs: docstrings edit (#185)
* edit complete * code-check touchup * Update connection.py Co-authored-by: Eric Ford <[email protected]>
1 parent 3a824dc commit fdd1a1f

40 files changed

+313
-310
lines changed

src/firebolt/async_db/_types.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,26 @@ def parse_datetime(date_string: str) -> datetime: # type: ignore
4646

4747

4848
def DateFromTicks(t: int) -> date:
49-
"""Convert ticks to date for firebolt db."""
49+
"""Convert `ticks` to `date` for Firebolt DB."""
5050
return datetime.fromtimestamp(t).date()
5151

5252

5353
def Time(hour: int, minute: int, second: int) -> None:
54-
"""Unsupported: construct time for firebolt db."""
55-
raise NotSupportedError("time is not supported by Firebolt")
54+
"""Unsupported: Construct `time`, for Firebolt DB."""
55+
raise NotSupportedError("The time construct is not supported by Firebolt")
5656

5757

5858
def TimeFromTicks(t: int) -> None:
59-
"""Unsupported: convert ticks to time for firebolt db."""
60-
raise NotSupportedError("time is not supported by Firebolt")
59+
"""Unsupported: Convert `ticks` to `time` for Firebolt DB."""
60+
raise NotSupportedError("The time construct is not supported by Firebolt")
6161

6262

6363
Timestamp = datetime
6464
TimestampFromTicks = datetime.fromtimestamp
6565

6666

6767
def Binary(value: str) -> str:
68-
"""Convert string to binary for firebolt db, does nothing."""
68+
"""Convert string to binary for Firebolt DB does nothing."""
6969
return value
7070

7171

@@ -89,7 +89,7 @@ def Binary(value: str) -> str:
8989

9090

9191
class ARRAY:
92-
"""Class for holding information about array column type in firebolt db."""
92+
"""Class for holding `array` column type information in Firebolt DB."""
9393

9494
_prefix = "Array("
9595

@@ -109,7 +109,7 @@ def __eq__(self, other: object) -> bool:
109109

110110

111111
class DECIMAL:
112-
"""Class for holding imformation about decimal value in firebolt db."""
112+
"""Class for holding `decimal` value information in Firebolt DB."""
113113

114114
_prefix = "Decimal("
115115

@@ -127,7 +127,7 @@ def __eq__(self, other: object) -> bool:
127127

128128

129129
class DATETIME64:
130-
"""Class for holding imformation about datetime64 value in firebolt db."""
130+
"""Class for holding `datetime64` value information in Firebolt DB."""
131131

132132
_prefix = "DateTime64("
133133

@@ -147,7 +147,7 @@ def __eq__(self, other: object) -> bool:
147147

148148

149149
class _InternalType(Enum):
150-
"""Enum of all internal firebolt types except for array."""
150+
"""Enum of all internal Firebolt types, except for `array`."""
151151

152152
# INT, INTEGER
153153
Int8 = "Int8"
@@ -182,7 +182,7 @@ class _InternalType(Enum):
182182

183183
@cached_property
184184
def python_type(self) -> type:
185-
"""Convert internal type to python type."""
185+
"""Convert internal type to Python type."""
186186
types = {
187187
_InternalType.Int8: int,
188188
_InternalType.UInt8: int,
@@ -205,7 +205,7 @@ def python_type(self) -> type:
205205

206206

207207
def parse_type(raw_type: str) -> Union[type, ARRAY, DECIMAL, DATETIME64]:
208-
"""Parse typename, provided by query metadata into python type."""
208+
"""Parse typename provided by query metadata into Python type."""
209209
if not isinstance(raw_type, str):
210210
raise DataError(f"Invalid typename {str(raw_type)}: str expected")
211211
# Handle arrays
@@ -244,7 +244,7 @@ def parse_value(
244244
value: RawColType,
245245
ctype: Union[type, ARRAY, DECIMAL, DATETIME64],
246246
) -> ColType:
247-
"""Provided raw value and python type, parses first into python value."""
247+
"""Provided raw value, and Python type; parses first into Python value."""
248248
if value is None:
249249
return None
250250
if ctype in (int, str, float):
@@ -276,7 +276,7 @@ def parse_value(
276276

277277

278278
def format_value(value: ParameterType) -> str:
279-
"""For python value to be used in a SQL query"""
279+
"""For Python value to be used in a SQL query."""
280280
if isinstance(value, bool):
281281
return str(int(value))
282282
if isinstance(value, (int, float, Decimal)):
@@ -299,7 +299,7 @@ def format_value(value: ParameterType) -> str:
299299

300300
def format_statement(statement: Statement, parameters: Sequence[ParameterType]) -> str:
301301
"""
302-
Substitute placeholders in a sqlparse statement with provided values.
302+
Substitute placeholders in a `sqlparse` statement with provided values.
303303
"""
304304
idx = 0
305305

@@ -336,7 +336,10 @@ def process_token(token: Token) -> Token:
336336

337337

338338
def statement_to_set(statement: Statement) -> Optional[SetParameter]:
339-
"""Try to parse statement as a SET command. Return None if it's not a SET command"""
339+
"""
340+
Try to parse `statement` as a `SET` command.
341+
Return `None` if it's not a `SET` command.
342+
"""
340343
# Filter out meaningless tokens like Punctuation and Whitespaces
341344
tokens = [
342345
token
@@ -370,9 +373,8 @@ def split_format_sql(
370373
query: str, parameters: Sequence[Sequence[ParameterType]]
371374
) -> List[Union[str, SetParameter]]:
372375
"""
373-
Split a query into separate statement, and format it with parameters
374-
if it's a single statement
375-
Trying to format a multi-statement query would result in NotSupportedError
376+
Multi-statement query formatting will result in `NotSupportedError`.
377+
Instead, split a query into a separate statement and format with parameters.
376378
"""
377379
statements = parse_sql(query)
378380
if not statements:

src/firebolt/async_db/connection.py

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
DEFAULT_TIMEOUT_SECONDS: int = 5
3131
KEEPALIVE_FLAG: int = 1
3232
KEEPIDLE_RATE: int = 60 # seconds
33-
AUTH_CREDENTIALS_DEPRECATION_MESSAGE = """ Passing connection credentials directly to `connect` function is deprecated.
34-
Please consider passing Auth object instead.
33+
AUTH_CREDENTIALS_DEPRECATION_MESSAGE = """ Passing connection credentials
34+
directly to the `connect` function is deprecated.
35+
Pass the `Auth` object instead.
3536
Examples:
3637
>>> from firebolt.client.auth import UsernamePassword
3738
>>> ...
@@ -128,29 +129,29 @@ def _get_auth(
128129
access_token: Optional[str],
129130
use_token_cache: bool,
130131
) -> Auth:
131-
"""Create Auth class based on provided credentials.
132+
"""Create `Auth` class based on provided credentials.
132133
133-
If access_token is provided, it's used for Auth creation.
134-
Username and password are used otherwise.
134+
If `access_token` is provided, it's used for `Auth` creation.
135+
Otherwise, username/password are used.
135136
136137
Returns:
137-
Auth: auth object
138+
Auth: `auth object`
138139
139140
Raises:
140-
ConfigurationError: Invalid combination of credentials provided
141+
`ConfigurationError`: Invalid combination of credentials provided
141142
142143
"""
143144
if not access_token:
144145
if not username or not password:
145146
raise ConfigurationError(
146147
"Neither username/password nor access_token are provided. Provide one"
147-
" to authenticate"
148+
" to authenticate."
148149
)
149150
return UsernamePassword(username, password, use_token_cache)
150151
if username or password:
151152
raise ConfigurationError(
152-
"Either username/password and access_token are provided. Provide only one"
153-
" to authenticate"
153+
"Username/password and access_token are both provided. Provide only one"
154+
" to authenticate."
154155
)
155156
return Token(access_token)
156157

@@ -172,24 +173,24 @@ async def connect_inner(
172173
"""Connect to Firebolt database.
173174
174175
Args:
175-
database (str): Name of the database to connect
176-
username (Optional[str]): User name to use for authentication (Deprecated)
177-
password (Optional[str]): Password to use for authentication (Deprecated)
178-
access_token (Optional[str]): Authentication token to use insead of
176+
`database` (str): Name of the database to connect
177+
`username` (Optional[str]): User name to use for authentication (Deprecated)
178+
`password` (Optional[str]): Password to use for authentication (Deprecated)
179+
`access_token` (Optional[str]): Authentication token to use instead of
179180
credentials (Deprecated)
180-
auth (Auth)L Authentication object
181-
engine_name (Optional[str]): The name of the engine to connect to
182-
engine_url (Optional[str]): The engine endpoint to use
183-
account_name (Optional[str]): For customers with multiple accounts;
184-
if None uses default.
185-
api_endpoint (str): Firebolt API endpoint. Used for authentication.
186-
use_token_cache (bool): Cached authentication token in filesystem.
181+
`auth` (Auth)L Authentication object.
182+
`engine_name` (Optional[str]): Name of the engine to connect to
183+
`engine_url` (Optional[str]): The engine endpoint to use
184+
`account_name` (Optional[str]): For customers with multiple accounts;
185+
if none, default is used
186+
`api_endpoint` (str): Firebolt API endpoint. Used for authentication
187+
`use_token_cache` (bool): Cached authentication token in filesystem
187188
Default: True
188-
additional_parameters (Optional[Dict]): Dictionary of less widely-used
189-
arguments for connection.
189+
`additional_parameters` (Optional[Dict]): Dictionary of less widely-used
190+
arguments for connection
190191
191192
Note:
192-
Providing both `engine_name` and `engine_url` would result in an error.
193+
Providing both `engine_name` and `engine_url` will result in an error
193194
194195
"""
195196
# These parameters are optional in function signature
@@ -251,11 +252,12 @@ async def connect_inner(
251252

252253
class OverriddenHttpBackend(AutoBackend):
253254
"""
254-
This class is a short-term solution for TCP keep-alive issue:
255+
`OverriddenHttpBackend` is a short-term solution for the TCP
256+
connection idle timeout issue described in the following article:
255257
https://docs.aws.amazon.com/elasticloadbalancing/latest/network/network-load-balancers.html#connection-idle-timeout
256-
Since httpx creates a connection right before executing a request
257-
backend has to be overridden in order to set the socket KEEPALIVE
258-
and KEEPIDLE settings.
258+
Since httpx creates a connection right before executing a request, the
259+
backend must be overridden to set the socket to `KEEPALIVE`
260+
and `KEEPIDLE` settings.
259261
"""
260262

261263
async def connect_tcp(
@@ -330,7 +332,7 @@ def _cursor(self, **kwargs: Any) -> BaseCursor:
330332
"""
331333

332334
if self.closed:
333-
raise ConnectionClosedError("Unable to create cursor: connection closed")
335+
raise ConnectionClosedError("Unable to create cursor: connection closed.")
334336

335337
c = self.cursor_class(self._client, self, **kwargs)
336338
self._cursors.append(c)
@@ -354,7 +356,7 @@ async def _aclose(self) -> None:
354356

355357
@property
356358
def closed(self) -> bool:
357-
"""True if connection is closed, False otherwise."""
359+
"""`True if connection is closed; False otherwise."""
358360
return self._is_closed
359361

360362
def _remove_cursor(self, cursor: Cursor) -> None:
@@ -365,28 +367,28 @@ def _remove_cursor(self, cursor: Cursor) -> None:
365367
pass
366368

367369
def commit(self) -> None:
368-
"""Does nothing since Firebolt doesn't have transactions"""
370+
"""Does nothing since Firebolt doesn't have transactions."""
369371

370372
if self.closed:
371-
raise ConnectionClosedError("Unable to commit: connection closed")
373+
raise ConnectionClosedError("Unable to commit: Connection closed.")
372374

373375

374376
class Connection(BaseConnection):
375377
"""
376-
Firebolt asyncronous database connection class. Implements `PEP 249`_.
378+
Firebolt asynchronous database connection class. Implements `PEP 249`_.
377379
378380
Args:
379-
engine_url: Firebolt database engine REST API url
380-
database: Firebolt database name
381-
username: Firebolt account username
382-
password: Firebolt account password
383-
api_endpoint: Optional. Firebolt API endpoint. Used for authentication.
384-
connector_versions: Optional. Tuple of connector name and version or
385-
list of tuples of your connector stack. Useful for tracking custom
381+
`engine_url`: Firebolt database engine REST API url
382+
`database`: Firebolt database name
383+
`username`: Firebolt account username
384+
`password`: Firebolt account password
385+
`api_endpoint`: Optional. Firebolt API endpoint used for authentication
386+
`connector_versions`: Optional. Tuple of connector name and version, or
387+
a list of tuples of your connector stack. Useful for tracking custom
386388
connector usage.
387389
388390
Note:
389-
Firebolt currenly doesn't support transactions
391+
Firebolt does not support transactions,
390392
so commit and rollback methods are not implemented.
391393
392394
.. _PEP 249:
@@ -406,7 +408,7 @@ def cursor(self) -> Cursor:
406408
# Context manager support
407409
async def __aenter__(self) -> Connection:
408410
if self.closed:
409-
raise ConnectionClosedError("Connection is already closed")
411+
raise ConnectionClosedError("Connection is already closed.")
410412
return self
411413

412414
async def __aexit__(

0 commit comments

Comments
 (0)