You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove environment variables from default function arguments
Problem
Using environment variables as default arguments in function definitions is problematic because:
Default arguments are evaluated at function definition time, not at runtime
This can lead to confusing behavior where changes to environment variables after module import don't affect the default values
Users may incorrectly assume that changing FOCOOS_CONFIG.focoos_api_key or FOCOOS_CONFIG.default_host_url at runtime will update the default arguments
Bug Example
# Initial configFOCOOS_CONFIG.focoos_api_key="key1"# Import the module - default args are evaluated herefromfocoosimportFocoosClient# Change config - users might expect this to affect new client instancesFOCOOS_CONFIG.focoos_api_key="key2"# Create new client without explicit api_keyclient=FocoosClient()
print(client.api_key) # Prints "key1", NOT "key2" as users might expect!
def__init__(
self,
api_key: str|None=None,
host_url: str|None=None,
):
""" Initializes the Focoos API client. Args: api_key (str, optional): API key for authentication. host_url (str, optional): Base URL for Focoos API. """self.api_key=api_keyorFOCOOS_CONFIG.focoos_api_keyself.host_url=host_urlorFOCOOS_CONFIG.default_host_url
Benefits
More explicit handling of configuration values
Runtime changes to environment variables will work as expected
The text was updated successfully, but these errors were encountered:
Replace api_key: str | None = None with api_key: Optional[str] = None for better compatibility with Python versions >=3.8. This ensures broader accessibility for the SDK, even if we later downgrade from 3.10.
Remove environment variables from default function arguments
Problem
Using environment variables as default arguments in function definitions is problematic because:
FOCOOS_CONFIG.focoos_api_key
orFOCOOS_CONFIG.default_host_url
at runtime will update the default argumentsBug Example
Current code
Proposed code
Benefits
The text was updated successfully, but these errors were encountered: