Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py: Ensure DRIVER_PATH_ENV_KEY defaults to string #14862

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

lauromoura
Copy link
Contributor

@lauromoura lauromoura commented Dec 6, 2024

User description

Description

Follow up to PR #14528, to avoid os.getenv raising TypeError in env_path when driver_path_env_key is not passed to Service constructor.

This happens, for example, with the WPEWebKit driver, which currently ignores driver_path_env_key, as the executable WPEWebDriver is usually available on $PATH (which is set either natively or through other test scripts).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Bug fix


Description

  • Added a parameter description for driver_path_env_key in the Service class docstring.
  • Set the DRIVER_PATH_ENV_KEY to default to an empty string if not provided, preventing TypeError when os.getenv is called.
  • This change ensures compatibility with drivers like WPEWebKit that do not use driver_path_env_key.

Changes walkthrough 📝

Relevant files
Bug fix
service.py
Ensure DRIVER_PATH_ENV_KEY defaults to an empty string     

py/selenium/webdriver/common/service.py

  • Added a parameter description for driver_path_env_key.
  • Set default value for DRIVER_PATH_ENV_KEY to an empty string.
  • +2/-1     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

    qodo-merge-pro bot commented Dec 6, 2024

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Code Style
    Consider making DRIVER_PATH_ENV_KEY a class variable with default value instead of instance variable, since it represents a constant configuration value

    Copy link
    Contributor

    qodo-merge-pro bot commented Dec 6, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    Using None instead of an empty string better represents the absence of an environment variable key

    The empty string default for DRIVER_PATH_ENV_KEY could cause issues when checking
    environment variables. Consider using None as the default value to clearly indicate
    no environment key is specified.

    py/selenium/webdriver/common/service.py [79]

    -self.DRIVER_PATH_ENV_KEY = driver_path_env_key or ""
    +self.DRIVER_PATH_ENV_KEY = driver_path_env_key or None
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Using None as a default value is more semantically correct for representing the absence of an environment variable key, making the code's intent clearer and preventing potential issues when checking environment variables.

    7

    💡 Need additional feedback ? start a PR chat

    @lauromoura
    Copy link
    Contributor Author

    PR Code Suggestions ✨

    Explore these optional code suggestions:
    Category Suggestion Score
    General
    Using None instead of an empty string better represents the absence of an environment variable key

    The empty string default for DRIVER_PATH_ENV_KEY could cause issues when checking environment variables. Consider using None as the default value to clearly indicate no environment key is specified.

    py/selenium/webdriver/common/service.py [79]

    -self.DRIVER_PATH_ENV_KEY = driver_path_env_key or ""
    +self.DRIVER_PATH_ENV_KEY = driver_path_env_key or None
    * [ ]  **Apply this suggestion**
    

    Suggestion importance[1-10]: 7

    Why: Using None as a default value is more semantically correct for representing the absence of an environment variable key, making the code's intent clearer and preventing potential issues when checking environment variables.
    7

    💡 Need additional feedback ? start a PR chat

    Maybe, based on this feedback, it'd be better to replace "" with an if in env_path() to guard the call to os.getenv?

    Copy link
    Contributor

    @Delta456 Delta456 left a comment

    Choose a reason for hiding this comment

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

    It should default to an empty string imo so this can be merged!

    Follow up to PR SeleniumHQ#14528, to avoid `os.getenv` raising `TypeError`
    in `env_path` when `driver_path_env_key` is not passed to `Service`
    constructor.
    @lauromoura lauromoura force-pushed the fix_driver_path_env_key_type branch from 84f41bd to a3812fa Compare December 12, 2024 16:46
    @lauromoura
    Copy link
    Contributor Author

    Updated the patch to keep the recommendation of using "None" to indicate the absence of value.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants