Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
Do not use mutable default arguments
Browse files Browse the repository at this point in the history
Using mutable default arguments is a common Python problem, see e.g.
https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments

In this specific case the default argument even tries to setup some
infrastructure settings at import time, which can potentially fail.
  • Loading branch information
Martin Lambertsen committed Jul 9, 2024
1 parent 7fc8509 commit ffdcdb9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.3.2] - TBD

### Added

### Changed
- Do not use mutable default arguments for HttpxRequestAdapter.[#383](https://github.com/microsoft/kiota-http-python/pull/383)

## [1.3.1] - 2024-02-13

### Added
Expand Down
2 changes: 1 addition & 1 deletion kiota_http/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION: str = '1.3.1'
VERSION: str = '1.3.2'
26 changes: 12 additions & 14 deletions kiota_http/httpx_request_adapter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""HTTPX client request adapter."""
import re
from collections.abc import AsyncIterable, Iterable
from datetime import datetime
from typing import Any, Dict, Generic, List, Optional, TypeVar, Union
from urllib import parse
from urllib.parse import unquote

import httpx
from kiota_abstractions.api_client_builder import (
Expand Down Expand Up @@ -63,29 +61,29 @@ class HttpxRequestAdapter(RequestAdapter, Generic[ModelType]):
def __init__(
self,
authentication_provider: AuthenticationProvider,
parse_node_factory: ParseNodeFactory = ParseNodeFactoryRegistry(),
serialization_writer_factory:
SerializationWriterFactory = SerializationWriterFactoryRegistry(),
http_client: httpx.AsyncClient = KiotaClientFactory.create_with_default_middleware(),
base_url: str = "",
observability_options=ObservabilityOptions(),
parse_node_factory: Optional[ParseNodeFactory] = None,
serialization_writer_factory: Optional[SerializationWriterFactory] = None,
http_client: Optional[httpx.AsyncClient] = None,
base_url: Optional[str] = None,
observability_options: Optional[ObservabilityOptions] = None,
) -> None:
if not authentication_provider:
raise TypeError("Authentication provider cannot be null")
self._authentication_provider = authentication_provider
if not parse_node_factory:
raise TypeError("Parse node factory cannot be null")
parse_node_factory = ParseNodeFactoryRegistry()
self._parse_node_factory = parse_node_factory
if not serialization_writer_factory:
raise TypeError("Serialization writer factory cannot be null")
serialization_writer_factory = SerializationWriterFactoryRegistry()
self._serialization_writer_factory = serialization_writer_factory
if not http_client:
raise TypeError("Http Client cannot be null")
if not observability_options:
observability_options = ObservabilityOptions()

http_client = KiotaClientFactory.create_with_default_middleware()
self._http_client = http_client
if not base_url:
base_url = ""
self._base_url: str = base_url
if not observability_options:
observability_options = ObservabilityOptions()
self.observability_options = observability_options

@property
Expand Down

0 comments on commit ffdcdb9

Please sign in to comment.