Skip to content

PYTHON-6228 Enable ruff rules UP007 and UP045 to use | instead of Uni… - #3183

Open
NoahStapp wants to merge 1 commit into
mongodb:mainfrom
NoahStapp:PYTHON-6228
Open

NoahStapp wants to merge 1 commit into
mongodb:mainfrom
NoahStapp:PYTHON-6228

Conversation

@NoahStapp

@NoahStapp NoahStapp commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

…on and Optional

PYTHON-6228

Changes in this PR

Remove the suppression of UP007 and UP045.

Test Plan

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

@NoahStapp
NoahStapp requested a review from a team as a code owner November 6, 2026 16:36
@NoahStapp
NoahStapp requested review from aclark4life and a balanced review from Copilot November 6, 2026 16:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for this union and optional annotation modernization.

No open issues 🎉

What changed in this PR

This PR standardizes union and optional type annotations across PyMongo, BSON, GridFS, and supporting tests using | syntax.

Changes:

  • Enables Ruff rules UP007 and UP045 by removing their suppressions.
  • Converts annotations and type aliases to X | Y and X | None, removing unused typing imports.
  • Updates signature assertions to expect the new annotation format.
File Description
test/​unified_format.py Updates primary-address return annotation.
test/​unified_format_shared.py Converts event-listener union annotations.
test/​test_typing.py Converts bulk-operation union annotations.
test/​test_encryption.py Updates optional encryption arguments.
test/​test_database.py Converts collection-filter annotation.
test/​test_comment.py Updates expected comment annotation string.
test/​test_client_metadata.py Converts optional metadata annotations.
test/​test_bulk.py Updates optional write-concern annotation.
test/​performance/​perf_test.py Converts operation and client annotations.
test/​performance/​async_perf_test.py Converts async benchmark operation annotations.
test/​helpers.py Updates optional join timeout annotation.
test/​asynchronous/​unified_format.py Updates primary-address return annotation.
test/​asynchronous/​test_encryption.py Updates optional encryption arguments.
test/​asynchronous/​test_database.py Converts collection-filter annotation.
test/​asynchronous/​test_comment.py Updates expected comment annotation string.
test/​asynchronous/​test_client_metadata.py Converts optional metadata annotations.
test/​asynchronous/​test_bulk.py Updates optional write-concern annotation.
test/​asynchronous/​helpers.py Updates optional async join timeout annotation.
pyproject.toml Enables Ruff UP007 and UP045.
pymongo/​write_concern.py Converts write-concern option annotations.
pymongo/​uri_parser_shared.py Converts shared URI parsing annotations.
pymongo/​typings.py Updates address alias and optional helper annotation.
pymongo/​topology_shared.py Converts shared topology annotations.
pymongo/​topology_description.py Converts topology state and selection annotations.
pymongo/​synchronous/​uri_parser.py Updates generated URI parser annotations.
pymongo/​synchronous/​topology.py Updates generated topology annotations.
pymongo/​synchronous/​srv_resolver.py Updates generated DNS resolver annotations.
pymongo/​synchronous/​settings.py Updates generated topology settings annotations.
pymongo/​synchronous/​server.py Updates generated server annotations.
pymongo/​synchronous/​pool.py Updates generated connection-pool annotations.
pymongo/​synchronous/​monitor.py Updates generated monitoring annotations.
pymongo/​synchronous/​cursor.py Updates generated cursor annotations.
pymongo/​synchronous/​cursor_base.py Updates generated cursor-base annotations and cast.
pymongo/​synchronous/​command_runner.py Updates generated command execution annotations.
pymongo/​synchronous/​command_cursor.py Updates generated command cursor annotations.
pymongo/​synchronous/​client_session.py Updates generated session and transaction annotations.
pymongo/​synchronous/​client_bulk.py Updates generated client bulk-write annotations.
pymongo/​synchronous/​change_stream.py Updates generated change-stream annotations.
pymongo/​synchronous/​bulk.py Updates generated collection bulk-write annotations.
pymongo/​synchronous/​auth_oidc.py Updates generated OIDC authentication annotations.
pymongo/​synchronous/​aggregation.py Updates generated aggregation annotations.
pymongo/​synchronous/​_kms_connect.py Updates generated KMS connection annotations.
pymongo/​ssl_support.py Converts TLS context annotations.
pymongo/​socket_checker.py Converts socket-checking annotations.
pymongo/​settings_shared.py Converts shared topology settings annotations.
pymongo/​server_selectors.py Converts server-selection annotations.
pymongo/​server_description.py Converts server state annotations.
pymongo/​server_api.py Converts Stable API option annotations.
pymongo/​saslprep.py Converts optional SASLprep flag annotations.
pymongo/​results.py Converts optional write-result annotations.
pymongo/​response.py Converts optional response duration annotations.
pymongo/​read_preferences.py Converts read-preference and latency annotations.
pymongo/​read_concern.py Converts optional read-concern level annotations.
pymongo/​pyopenssl_context.py Converts OpenSSL wrapper annotations.
pymongo/​pool_options.py Converts pool configuration and metadata annotations.
pymongo/​periodic_executor.py Converts background executor annotations.
pymongo/​operations.py Converts index aliases and write-operation annotations.
pymongo/​ocsp_support.py Converts certificate and OCSP annotations.
pymongo/​ocsp_cache.py Converts optional OCSP timestamp annotations.
pymongo/​mongo_client_shared.py Converts shared retry annotations.
pymongo/​lock.py Converts condition and timeout annotations.
pymongo/​helpers_shared.py Converts shared utility annotations.
pymongo/​hello.py Converts optional handshake field annotations.
pymongo/​errors.py Converts exception detail annotations.
pymongo/​encryption_shared.py Converts optional key-rewrap result annotations.
pymongo/​encryption_options.py Converts encryption configuration annotations.
pymongo/​driver_info.py Converts optional driver metadata annotations.
pymongo/​daemon.py Converts subprocess helper annotations.
pymongo/​compression_support.py Converts compressor and context annotations.
pymongo/​collation.py Converts collation option annotations.
pymongo/​client_options.py Converts client option annotations and listener cast.
pymongo/​change_stream_shared.py Converts shared change-stream annotations.
pymongo/​bulk_shared.py Converts shared collection bulk-write annotations.
pymongo/​auth_shared.py Converts shared authentication annotations.
pymongo/​auth_oidc_shared.py Converts OIDC data and callback annotations.
pymongo/​asynchronous/​uri_parser.py Converts async URI parser annotations.
pymongo/​asynchronous/​topology.py Converts async topology annotations.
pymongo/​asynchronous/​srv_resolver.py Converts async DNS resolver annotations.
pymongo/​asynchronous/​settings.py Converts async topology settings annotations.
pymongo/​asynchronous/​server.py Converts async server annotations.
pymongo/​asynchronous/​pool.py Converts async connection-pool annotations.
pymongo/​asynchronous/​monitor.py Converts async monitoring annotations.
pymongo/​asynchronous/​cursor.py Converts async cursor annotations.
pymongo/​asynchronous/​cursor_base.py Converts async cursor-base annotations and cast.
pymongo/​asynchronous/​command_runner.py Converts async command execution annotations.
pymongo/​asynchronous/​command_cursor.py Converts async command cursor annotations.
pymongo/​asynchronous/​client_session.py Converts async session and transaction annotations.
pymongo/​asynchronous/​client_bulk.py Converts async client bulk-write annotations.
pymongo/​asynchronous/​change_stream.py Converts async change-stream annotations.
pymongo/​asynchronous/​bulk.py Converts async collection bulk-write annotations.
pymongo/​asynchronous/​auth_oidc.py Converts async OIDC authentication annotations.
pymongo/​asynchronous/​aggregation.py Converts async aggregation annotations.
pymongo/​asynchronous/​_kms_connect.py Converts async KMS connection annotations.
pymongo/​_version.py Converts version component annotations.
pymongo/​_telemetry.py Converts telemetry event annotations.
pymongo/​_psl.py Converts optional public-suffix cache annotation.
pymongo/​_op_id.py Converts optional operation identifier annotations.
pymongo/​_kms_connect_shared.py Converts shared KMS proxy annotations.
pymongo/​_csot.py Converts timeout context annotations.
pymongo/​_client_bulk_shared.py Converts shared client bulk-write annotations.
pymongo/​_azure_helpers.py Converts optional Azure client identifier annotation.
pymongo/​_asyncio_lock.py Converts async lock state annotations.
pymongo/​__init__.py Converts public timeout parameter annotation.
gridfs/​grid_file_shared.py Converts optional GridFS property flags.
fuzz/​fuzz_decode.py Converts optional decoded-document annotation.
fuzz/​fuzz_decode_all.py Converts optional decoded-list annotation.
bson/​tz_util.py Converts timezone annotations.
bson/​timestamp.py Converts timestamp input annotation.
bson/​son.py Converts ordered-document annotations.
bson/​regex.py Converts regex flags annotation.
bson/​raw_bson.py Converts raw-document annotations.
bson/​objectid.py Converts ObjectId input annotation.
bson/​json_util.py Converts Extended JSON annotations.
bson/​errors.py Converts optional invalid-document annotation.
bson/​decimal128.py Converts decimal input type alias.
bson/​dbref.py Converts database reference annotations.
bson/​datetime_ms.py Converts datetime value and comparison annotations.
bson/​codec_options.py Converts codec alias and option annotations.
bson/​code.py Converts JavaScript code and scope annotations.
bson/​binary.py Converts binary and vector annotations.
bson/​__init__.py Converts BSON utility annotations and decode cast.

Review effort: Balanced

@blink1073

Copy link
Copy Markdown
Member

I think we'll want to add this merge commit to https://github.com/mongodb/mongo-python-driver/blob/main/.git-blame-ignore-revs

@NoahStapp

Copy link
Copy Markdown
Contributor Author

I think we'll want to add this merge commit to https://github.com/mongodb/mongo-python-driver/blob/main/.git-blame-ignore-revs

Probably do the same for all of these linting changes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants