selenium icon indicating copy to clipboard operation
selenium copied to clipboard

`py/test/selenium/webdriver/common/network.py`: remove python 2 code

Open Delta456 opened this issue 1 year ago • 3 comments

User description

Thanks for contributing to Selenium! A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines. Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Removes dead Python 2 code from py/test/selenium/webdriver/common/network.py as Python 2 support is now dropped

Motivation and Context

Migrate to Python 3 from Python 2

Types of changes

  • [x] 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

  • [x] 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.
  • [x] All new and existing tests passed.

PR Type

enhancement


Description

  • Removed obsolete Python 2 compatibility code from py/test/selenium/webdriver/common/network.py.
  • Simplified the _bytes function to only support Python 3, reflecting the project's migration to Python 3.

Changes walkthrough 📝

Relevant files
Enhancement
network.py
Remove Python 2 compatibility code from network module     

py/test/selenium/webdriver/common/network.py

  • Removed Python 2 compatibility code.
  • Simplified _bytes function to only support Python 3.
  • +1/-4     

    💡 PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Delta456 avatar Sep 16 '24 11:09 Delta456

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ No key issues to review

    qodo-code-review[bot] avatar Sep 16 '24 11:09 qodo-code-review[bot]

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Use a context manager for the socket to ensure proper resource management

    Consider using a context manager (with statement) for the socket to ensure it's
    properly closed after use.

    py/test/selenium/webdriver/common/network.py [30-32]

    -sckt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    -return socket.inet_ntoa(
    -    fcntl.ioctl(sckt.fileno(), 0x8915, struct.pack("256s", _bytes(ifname[:15], "utf-8")))[20:24]  # SIOCGIFADDR
    +with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sckt:
    +    return socket.inet_ntoa(
    +        fcntl.ioctl(sckt.fileno(), 0x8915, struct.pack("256s", _bytes(ifname[:15], "utf-8")))[20:24]  # SIOCGIFADDR
     
    
    • [ ] Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: Using a context manager for the socket is a best practice that ensures proper resource management and prevents potential resource leaks, making it a valuable improvement.

    9
    Enhancement
    Move the helper function outside the main function to improve code structure

    Consider moving the _bytes function outside of get_interface_ip to improve
    readability and reduce function nesting.

    py/test/selenium/webdriver/common/network.py [26-32]

    +def _bytes(value, encoding):
    +    return bytes(value, encoding)
    +
     def get_interface_ip(ifname):
    -    def _bytes(value, encoding):
    -        return bytes(value, encoding)
    -
         sckt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
         return socket.inet_ntoa(
             fcntl.ioctl(sckt.fileno(), 0x8915, struct.pack("256s", _bytes(ifname[:15], "utf-8")))[20:24]  # SIOCGIFADDR
     
    
    • [ ] Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Moving the _bytes function outside of get_interface_ip can improve readability and maintainability by reducing nesting, but it is not a critical change.

    7

    qodo-code-review[bot] avatar Sep 16 '24 11:09 qodo-code-review[bot]

    Codecov Report

    All modified and coverable lines are covered by tests :white_check_mark:

    Project coverage is 57.66%. Comparing base (b2ef56a) to head (12d9ccf). Report is 41 commits behind head on trunk.

    Additional details and impacted files
    @@            Coverage Diff             @@
    ##            trunk   #14502      +/-   ##
    ==========================================
    - Coverage   57.67%   57.66%   -0.02%     
    ==========================================
      Files          89       89              
      Lines        5578     5586       +8     
      Branches      240      245       +5     
    ==========================================
    + Hits         3217     3221       +4     
    + Misses       2121     2120       -1     
    - Partials      240      245       +5     
    

    :umbrella: View full report in Codecov by Sentry.
    :loudspeaker: Have feedback on the report? Share it here.

    codecov[bot] avatar Sep 18 '24 16:09 codecov[bot]

    Test failures seen here are unrelated to the changes in this PR.

    RBE Test failures:

    • //dotnet/test/common:DevTools/DevToolsConsoleTest-edge
    • //dotnet/test/common:DevTools/DevToolsNetworkTest-chrome
    • //java/test/org/openqa/selenium/chrome:ChromeOptionsFunctionalTest-remote

    harsha509 avatar Oct 01 '24 13:10 harsha509