Skip to content

feat(abstractions): enhance HeadersCollection usability and dict interoperability - #816

Merged
Vincent Biret (baywet) merged 1 commit into
microsoft:mainfrom
hardikkaurani:feat/headers-collection-usability
Oct 21, 2026
Merged

Vincent Biret (baywet) merged 1 commit into
microsoft:mainfrom
hardikkaurani:feat/headers-collection-usability

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Description

Fixes #208

This PR addresses the usability improvements requested for HeadersCollection:

  1. Dictionary and HeadersCollection Constructor Initialization:
    HeadersCollection now accepts an optional initial headers parameter (Optional[Union[HeadersCollection, Mapping[str, Union[str, Iterable[str]]]]]), allowing direct instantiation from a dictionary or copy-construction from another HeadersCollection.
  2. add_all Dictionary Support:
    add_all now accepts either a HeadersCollection or any Mapping (dict) of header names to values (Union[str, Iterable[str]]), matching the docstring expectation and easing integration across callers.
  3. Python Container / Mapping Protocol:
    Implements standard Python container magic methods:
    • __contains__: supports "header" in headers
    • __getitem__: supports headers["header"]
    • __setitem__: supports headers["header"] = "value"
    • __len__: supports len(headers)
    • __iter__: supports iterating header keys directly

Related Issue

Fixes #208

Testing

Added unit tests in packages/abstractions/tests/test_request_header.py:

  • test_init_with_dict
  • test_init_with_headers_collection
  • test_add_all_with_dict
  • test_container_methods

cc Vincent Biret (@baywet)

Copilot AI balanced review requested due to automatic review settings October 19, 2026 20:17
@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner October 19, 2026 20:17

This comment was marked as off-topic.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet), submitted this PR to resolve #208 by enabling dictionary and HeadersCollection constructor initialization, mapping support in add_all, and Python container protocol magic methods (in, [], len(), iter()). Comprehensive unit tests added in test_request_header.py. Ready for your review, thank you!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Empty-input handling, replacement assignment, and single-value header imports have unresolved correctness issues.

3 open issues

Review effort: Balanced

Comment thread packages/abstractions/kiota_abstractions/headers_collection.py Outdated
Comment thread packages/abstractions/kiota_abstractions/headers_collection.py Outdated
Comment thread packages/abstractions/kiota_abstractions/headers_collection.py Outdated
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicting changes, the author must resolve the conflicts before this pull request can be merged.

Copilot AI balanced review requested due to automatic review settings October 20, 2026 18:26
@hardikkaurani
Hardik K (hardikkaurani) force-pushed the feat/headers-collection-usability branch from 012435e to 4088ad1 Compare October 20, 2026 18:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown
Contributor

Conflicts have been resolved. A maintainer will take a look shortly.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet)!

I have resolved the merge conflicts with \main\ and addressed all review feedback:

  1. Empty-Input Handling:

    • Updated \�dd_all\ to only reject \None\ (\if headers is None:), allowing empty \HeadersCollection\ instances and empty mappings to complete cleanly as no-ops.
    • Updated \ est_request_information.py:29\ to an explicit initialization check (\�ssert request_info.headers is not None).
    • Added unit tests in \ est_request_header.py\ verifying initialization and \�dd_all\ with empty mappings/collections.
  2. Iterable Initialization & Single-Value Headers:

    • Materialized iterable values into a list when delegating to \self.add(key, list_values)\ so that single-value headers (e.g., \Content-Length) properly retain only the first value.
    • Added regression test \ est_init_iterable_single_value_header.
  3. Subscript Assignment Replacement:

    • Implemented _setitem_\ to replace existing header values on assignment (case-insensitively) rather than appending, and validates the replacement before mutating stored headers. Also added _delitem_.
    • Added tests covering repeated assignments, case-insensitivity, validation, and single-value header assignment.

All local quality gates and checks (\pytest\ 168/168, \mypy\ 0 issues in 48 files, \pylint\ 10.00/10, \yapf, \isort) pass cleanly. Ready for review!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

Previously reported regressions are addressed with regression tests, and no blocking issues remain.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@baywet Vincent Biret (baywet) left a comment

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.

Thanks for the contribution!

@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Oct 21, 2026
Copilot AI balanced review requested due to automatic review settings October 21, 2026 12:45
@baywet
Vincent Biret (baywet) force-pushed the feat/headers-collection-usability branch from 4088ad1 to f4c60bd Compare October 21, 2026 12:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonarqubecloud

Copy link
Copy Markdown

@baywet
Vincent Biret (baywet) merged commit 745dfee into microsoft:main Oct 21, 2026
69 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

HeadersCollection usability

3 participants