Skip to content

[Python] New _create method for aio.Metadata#41678

Closed
asheshvidyut wants to merge 46 commits intogrpc:masterfrom
asheshvidyut:fix-api
Closed

[Python] New _create method for aio.Metadata#41678
asheshvidyut wants to merge 46 commits intogrpc:masterfrom
asheshvidyut:fix-api

Conversation

@asheshvidyut
Copy link
Copy Markdown
Member

@asheshvidyut asheshvidyut commented Feb 19, 2026

This PR adds new create method for aio.Metadata, as described in the comment here - #40226 (comment)

Reason being from_tuple as the name says should actually create only from tuple whereas the method actually takes other arguments as well.

Hence we introduce the new _create method, which is internal as of now.

@asheshvidyut asheshvidyut added the release notes: no Indicates if PR should not be in release notes label Feb 19, 2026
@asheshvidyut asheshvidyut marked this pull request as ready for review February 19, 2026 08:37
Comment thread src/python/grpcio_tests/tests_aio/unit/_metadata_test.py Outdated
Comment thread src/python/grpcio/grpc/aio/_metadata.py Outdated
Comment thread src/python/grpcio/grpc/aio/_metadata.py Outdated
def _create(
cls,
raw_metadata: Optional[
Union[Self, Iterable[tuple[MetadataKey, MetadataValue]]]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you remember, we've considered moving the declaration of MetadatumType and MetadataType to this file, so then we'll be able to replace tuple[MetadataKey, MetadataValue] with MetadatumType

Comment thread src/python/grpcio/grpc/aio/_metadata.py Outdated
Comment thread src/python/grpcio/grpc/aio/_base_channel.py Outdated
@leuasseurfarrelds247-arch

This comment was marked as spam.

)

def test_create(self):
# 1. raw_metadata is None
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit for a follow up: remove numbering in the comments 1. ...

@typeguard.suppress_type_checks
def test_create_invalid_type(self):

# 2. raw_metadata is string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also number

def test_create_invalid_type(self):

# 2. raw_metadata is string
l = "key, value"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no need an extra variable here

# 2. raw_metadata is string
l = "key, value"
with self.assertRaises(ValueError) as container:
Metadata._create(l) # type: ignore
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

type: ignore should not be needed

def test_create_invalid_type(self):

# 2. raw_metadata is string
l = "key, value"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let's make the test string less confusing key, value

Copy link
Copy Markdown
Member

@sergiitk sergiitk left a comment

Choose a reason for hiding this comment

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

LGTM, small stuff that can be fixed in a follow up.

sergiitk pushed a commit to sergiitk/grpc that referenced this pull request Mar 17, 2026
This PR adds new create method for `aio.Metadata`, as described in the comment here  - grpc#40226 (comment)

Reason being `from_tuple` as the name says should actually create only from `tuple` whereas the method actually takes other arguments as well.

Hence we introduce the new `_create` method, which is internal as of now.

Closes grpc#41678

COPYBARA_INTEGRATE_REVIEW=grpc#41678 from asheshvidyut:fix-api c1a0281
PiperOrigin-RevId: 885107284
Zgoda91 pushed a commit to Zgoda91/grpc that referenced this pull request Mar 22, 2026
This PR adds new create method for `aio.Metadata`, as described in the comment here  - grpc#40226 (comment)

Reason being `from_tuple` as the name says should actually create only from `tuple` whereas the method actually takes other arguments as well.

Hence we introduce the new `_create` method, which is internal as of now.

Closes grpc#41678

COPYBARA_INTEGRATE_REVIEW=grpc#41678 from asheshvidyut:fix-api c1a0281
PiperOrigin-RevId: 885107284
sergiitk added a commit that referenced this pull request Mar 23, 2026
…1888)

Backport of #41678 to v1.80.x.
---
This PR adds new create method for `aio.Metadata`, as described in the
comment here -
#40226 (comment)

Reason being `from_tuple` as the name says should actually create only
from `tuple` whereas the method actually takes other arguments as well.

Hence we introduce the new `_create` method, which is internal as of
now.

Co-authored-by: Ashesh Vidyut <asheshvidyut@google.com>
asheshvidyut added a commit to asheshvidyut/grpc that referenced this pull request Mar 26, 2026
This PR adds new create method for `aio.Metadata`, as described in the comment here  - grpc#40226 (comment)

Reason being `from_tuple` as the name says should actually create only from `tuple` whereas the method actually takes other arguments as well.

Hence we introduce the new `_create` method, which is internal as of now.

Closes grpc#41678

COPYBARA_INTEGRATE_REVIEW=grpc#41678 from asheshvidyut:fix-api c1a0281
PiperOrigin-RevId: 885107284
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lang/Python priority/P0/RELEASE BLOCKER release notes: no Indicates if PR should not be in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants