Skip to content

Commit 6f5bda7

Browse files
committed
Remove property decorators
1 parent cee6c5a commit 6f5bda7

File tree

12 files changed

+48
-96
lines changed

12 files changed

+48
-96
lines changed

pymongo/asynchronous/client_bulk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ async def _execute_command(
537537
session._start_retryable_write()
538538
self.started_retryable_write = True
539539
session._apply_to(cmd, retryable, ReadPreference.PRIMARY, conn)
540-
session.leave_alive = True
540+
session._leave_alive = True
541541
conn.send_cluster_time(cmd, session, self.client)
542542
conn.add_server_api(cmd)
543543
# CSOT: apply timeout before encoding the command.

pymongo/asynchronous/client_session.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,9 @@ def __init__(
513513
# Is this an implicitly created session?
514514
self._implicit = implicit
515515
self._transaction = _Transaction(None, client)
516+
# Is this session attached to a cursor?
516517
self._attached_to_cursor = False
518+
# Should we leave the session alive when the cursor is closed?
517519
self._leave_alive = False
518520

519521
async def end_session(self) -> None:
@@ -590,32 +592,6 @@ def operation_time(self) -> Optional[Timestamp]:
590592
"""
591593
return self._operation_time
592594

593-
@property
594-
def _is_implicit(self) -> bool:
595-
"""Whether this session was implicitly created by the driver."""
596-
return self._implicit
597-
598-
@property
599-
def _is_attached_to_cursor(self) -> bool:
600-
"""Whether this session is owned by a cursor."""
601-
return self._attached_to_cursor
602-
603-
@_is_attached_to_cursor.setter
604-
def _is_attached_to_cursor(self, value: bool) -> None:
605-
self._attached_to_cursor = value
606-
607-
@property
608-
def leave_alive(self) -> bool:
609-
"""Whether to leave this session alive when it is
610-
no longer in use.
611-
Typically used for implicit sessions that are used for multiple operations within a single larger operation.
612-
"""
613-
return self._leave_alive
614-
615-
@leave_alive.setter
616-
def leave_alive(self, value: bool) -> None:
617-
self._leave_alive = value
618-
619595
def _inherit_option(self, name: str, val: _T) -> _T:
620596
"""Return the inherited TransactionOption value."""
621597
if val:

pymongo/asynchronous/command_cursor.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(
8080
self._timeout = self._collection.database.client.options.timeout
8181
self._session = session
8282
if self._session is not None:
83-
self._session._is_attached_to_cursor = True
83+
self._session._attached_to_cursor = True
8484
self._killed = self._id == 0
8585
self._comment = comment
8686
if self._killed:
@@ -197,7 +197,7 @@ def session(self) -> Optional[AsyncClientSession]:
197197
198198
.. versionadded:: 3.6
199199
"""
200-
if self._session and not self._session._is_implicit:
200+
if self._session and not self._session._implicit:
201201
return self._session
202202
return None
203203

@@ -220,8 +220,8 @@ def _die_no_lock(self) -> None:
220220
self._collection.database.client._cleanup_cursor_no_lock(
221221
cursor_id, address, self._sock_mgr, self._session
222222
)
223-
if self._session and self._session._is_implicit:
224-
self._session._is_attached_to_cursor = False
223+
if self._session and self._session._implicit:
224+
self._session._attached_to_cursor = False
225225
self._session = None
226226
self._sock_mgr = None
227227

@@ -234,14 +234,14 @@ async def _die_lock(self) -> None:
234234
self._sock_mgr,
235235
self._session,
236236
)
237-
if self._session and self._session._is_implicit:
238-
self._session._is_attached_to_cursor = False
237+
if self._session and self._session._implicit:
238+
self._session._attached_to_cursor = False
239239
self._session = None
240240
self._sock_mgr = None
241241

242242
def _end_session(self) -> None:
243-
if self._session and self._session._is_implicit and not self._session.leave_alive:
244-
self._session._is_attached_to_cursor = False
243+
if self._session and self._session._implicit and not self._session._leave_alive:
244+
self._session._attached_to_cursor = False
245245
self._session._end_implicit_session()
246246
self._session = None
247247

pymongo/asynchronous/cursor.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def __init__(
138138

139139
if session:
140140
self._session = session
141-
self._session._is_attached_to_cursor = True
141+
self._session._attached_to_cursor = True
142142
else:
143143
self._session = None
144144

@@ -149,7 +149,7 @@ def __init__(
149149
if not isinstance(limit, int):
150150
raise TypeError(f"limit must be an instance of int, not {type(limit)}")
151151
validate_boolean("no_cursor_timeout", no_cursor_timeout)
152-
if no_cursor_timeout and self._session and self._session._is_implicit:
152+
if no_cursor_timeout and self._session and self._session._implicit:
153153
warnings.warn(
154154
"use an explicit session with no_cursor_timeout=True "
155155
"otherwise the cursor may still timeout after "
@@ -282,7 +282,7 @@ def clone(self) -> AsyncCursor[_DocumentType]:
282282
def _clone(self, deepcopy: bool = True, base: Optional[AsyncCursor] = None) -> AsyncCursor: # type: ignore[type-arg]
283283
"""Internal clone helper."""
284284
if not base:
285-
if self._session and not self._session._is_implicit:
285+
if self._session and not self._session._implicit:
286286
base = self._clone_base(self._session)
287287
else:
288288
base = self._clone_base(None)
@@ -944,7 +944,7 @@ def session(self) -> Optional[AsyncClientSession]:
944944
945945
.. versionadded:: 3.6
946946
"""
947-
if self._session and not self._session._is_implicit:
947+
if self._session and not self._session._implicit:
948948
return self._session
949949
return None
950950

@@ -1035,8 +1035,8 @@ def _die_no_lock(self) -> None:
10351035
self._collection.database.client._cleanup_cursor_no_lock(
10361036
cursor_id, address, self._sock_mgr, self._session
10371037
)
1038-
if self._session and self._session._is_implicit:
1039-
self._session._is_attached_to_cursor = False
1038+
if self._session and self._session._implicit:
1039+
self._session._attached_to_cursor = False
10401040
self._session = None
10411041
self._sock_mgr = None
10421042

@@ -1055,8 +1055,8 @@ async def _die_lock(self) -> None:
10551055
self._sock_mgr,
10561056
self._session,
10571057
)
1058-
if self._session and self._session._is_implicit:
1059-
self._session._is_attached_to_cursor = False
1058+
if self._session and self._session._implicit:
1059+
self._session._attached_to_cursor = False
10601060
self._session = None
10611061
self._sock_mgr = None
10621062

pymongo/asynchronous/database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,8 @@ async def create_collection(
611611
common.validate_is_mapping("clusteredIndex", clustered_index)
612612

613613
async with self._client._tmp_session(session) as s:
614-
if s:
615-
s.leave_alive = True
614+
if s and not s.in_transaction:
615+
s._leave_alive = True
616616
# Skip this check in a transaction where listCollections is not
617617
# supported.
618618
if (

pymongo/asynchronous/mongo_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,7 @@ def _cleanup_cursor_no_lock(
21062106
# The cursor will be closed later in a different session.
21072107
if cursor_id or conn_mgr:
21082108
self._close_cursor_soon(cursor_id, address, conn_mgr)
2109-
if session and session._is_implicit and not session.leave_alive:
2109+
if session and session._implicit and not session._leave_alive:
21102110
session._end_implicit_session()
21112111

21122112
async def _cleanup_cursor_lock(
@@ -2138,7 +2138,7 @@ async def _cleanup_cursor_lock(
21382138
await self._close_cursor_now(cursor_id, address, session=session, conn_mgr=conn_mgr)
21392139
if conn_mgr:
21402140
await conn_mgr.close()
2141-
if session and session._is_implicit and not session.leave_alive:
2141+
if session and session._implicit and not session._leave_alive:
21422142
session._end_implicit_session()
21432143

21442144
async def _close_cursor_now(
@@ -2289,7 +2289,7 @@ async def _tmp_session(
22892289
raise
22902290
finally:
22912291
# Call end_session when we exit this scope.
2292-
if not s._is_attached_to_cursor:
2292+
if not s._attached_to_cursor:
22932293
await s.end_session()
22942294
else:
22952295
yield None

pymongo/synchronous/client_bulk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def _execute_command(
535535
session._start_retryable_write()
536536
self.started_retryable_write = True
537537
session._apply_to(cmd, retryable, ReadPreference.PRIMARY, conn)
538-
session.leave_alive = True
538+
session._leave_alive = True
539539
conn.send_cluster_time(cmd, session, self.client)
540540
conn.add_server_api(cmd)
541541
# CSOT: apply timeout before encoding the command.

pymongo/synchronous/client_session.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,9 @@ def __init__(
512512
# Is this an implicitly created session?
513513
self._implicit = implicit
514514
self._transaction = _Transaction(None, client)
515+
# Is this session attached to a cursor?
515516
self._attached_to_cursor = False
517+
# Should we leave the session alive when the cursor is closed?
516518
self._leave_alive = False
517519

518520
def end_session(self) -> None:
@@ -589,32 +591,6 @@ def operation_time(self) -> Optional[Timestamp]:
589591
"""
590592
return self._operation_time
591593

592-
@property
593-
def _is_implicit(self) -> bool:
594-
"""Whether this session was implicitly created by the driver."""
595-
return self._implicit
596-
597-
@property
598-
def _is_attached_to_cursor(self) -> bool:
599-
"""Whether this session is owned by a cursor."""
600-
return self._attached_to_cursor
601-
602-
@_is_attached_to_cursor.setter
603-
def _is_attached_to_cursor(self, value: bool) -> None:
604-
self._attached_to_cursor = value
605-
606-
@property
607-
def leave_alive(self) -> bool:
608-
"""Whether to leave this session alive when it is
609-
no longer in use.
610-
Typically used for implicit sessions that are used for multiple operations within a single larger operation.
611-
"""
612-
return self._leave_alive
613-
614-
@leave_alive.setter
615-
def leave_alive(self, value: bool) -> None:
616-
self._leave_alive = value
617-
618594
def _inherit_option(self, name: str, val: _T) -> _T:
619595
"""Return the inherited TransactionOption value."""
620596
if val:

pymongo/synchronous/command_cursor.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(
8080
self._timeout = self._collection.database.client.options.timeout
8181
self._session = session
8282
if self._session is not None:
83-
self._session._is_attached_to_cursor = True
83+
self._session._attached_to_cursor = True
8484
self._killed = self._id == 0
8585
self._comment = comment
8686
if self._killed:
@@ -197,7 +197,7 @@ def session(self) -> Optional[ClientSession]:
197197
198198
.. versionadded:: 3.6
199199
"""
200-
if self._session and not self._session._is_implicit:
200+
if self._session and not self._session._implicit:
201201
return self._session
202202
return None
203203

@@ -220,8 +220,8 @@ def _die_no_lock(self) -> None:
220220
self._collection.database.client._cleanup_cursor_no_lock(
221221
cursor_id, address, self._sock_mgr, self._session
222222
)
223-
if self._session and self._session._is_implicit:
224-
self._session._is_attached_to_cursor = False
223+
if self._session and self._session._implicit:
224+
self._session._attached_to_cursor = False
225225
self._session = None
226226
self._sock_mgr = None
227227

@@ -234,14 +234,14 @@ def _die_lock(self) -> None:
234234
self._sock_mgr,
235235
self._session,
236236
)
237-
if self._session and self._session._is_implicit:
238-
self._session._is_attached_to_cursor = False
237+
if self._session and self._session._implicit:
238+
self._session._attached_to_cursor = False
239239
self._session = None
240240
self._sock_mgr = None
241241

242242
def _end_session(self) -> None:
243-
if self._session and self._session._is_implicit and not self._session.leave_alive:
244-
self._session._is_attached_to_cursor = False
243+
if self._session and self._session._implicit and not self._session._leave_alive:
244+
self._session._attached_to_cursor = False
245245
self._session._end_implicit_session()
246246
self._session = None
247247

pymongo/synchronous/cursor.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def __init__(
138138

139139
if session:
140140
self._session = session
141-
self._session._is_attached_to_cursor = True
141+
self._session._attached_to_cursor = True
142142
else:
143143
self._session = None
144144

@@ -149,7 +149,7 @@ def __init__(
149149
if not isinstance(limit, int):
150150
raise TypeError(f"limit must be an instance of int, not {type(limit)}")
151151
validate_boolean("no_cursor_timeout", no_cursor_timeout)
152-
if no_cursor_timeout and self._session and self._session._is_implicit:
152+
if no_cursor_timeout and self._session and self._session._implicit:
153153
warnings.warn(
154154
"use an explicit session with no_cursor_timeout=True "
155155
"otherwise the cursor may still timeout after "
@@ -282,7 +282,7 @@ def clone(self) -> Cursor[_DocumentType]:
282282
def _clone(self, deepcopy: bool = True, base: Optional[Cursor] = None) -> Cursor: # type: ignore[type-arg]
283283
"""Internal clone helper."""
284284
if not base:
285-
if self._session and not self._session._is_implicit:
285+
if self._session and not self._session._implicit:
286286
base = self._clone_base(self._session)
287287
else:
288288
base = self._clone_base(None)
@@ -942,7 +942,7 @@ def session(self) -> Optional[ClientSession]:
942942
943943
.. versionadded:: 3.6
944944
"""
945-
if self._session and not self._session._is_implicit:
945+
if self._session and not self._session._implicit:
946946
return self._session
947947
return None
948948

@@ -1033,8 +1033,8 @@ def _die_no_lock(self) -> None:
10331033
self._collection.database.client._cleanup_cursor_no_lock(
10341034
cursor_id, address, self._sock_mgr, self._session
10351035
)
1036-
if self._session and self._session._is_implicit:
1037-
self._session._is_attached_to_cursor = False
1036+
if self._session and self._session._implicit:
1037+
self._session._attached_to_cursor = False
10381038
self._session = None
10391039
self._sock_mgr = None
10401040

@@ -1053,8 +1053,8 @@ def _die_lock(self) -> None:
10531053
self._sock_mgr,
10541054
self._session,
10551055
)
1056-
if self._session and self._session._is_implicit:
1057-
self._session._is_attached_to_cursor = False
1056+
if self._session and self._session._implicit:
1057+
self._session._attached_to_cursor = False
10581058
self._session = None
10591059
self._sock_mgr = None
10601060

0 commit comments

Comments
 (0)