Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: psf/requests
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: codeflash-ai/requests
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Nov 22, 2024

  1. ⚡️ Speed up function _init by 11%

    To optimize the given Python code for better performance, we can make a few improvements. This includes eliminating unnecessary global variable modifications and reducing redundant iterations. Here’s an optimized version of the code.
    
    
    
    ### Changes Made.
    1. **Merged Initialization Loops**: Instead of updating the `__doc__` attribute in a separate loop, the document string is constructed during the main loop.
    2. **Minimized Global Access**: The global `__doc__` is only modified once after the loop, avoiding repeated global lookups.
    3. **Avoided Redundant Code**: Reduced the code by merging the setting of doc lines into a single list append inside the loop.
    
    These changes should make the function more efficient in terms of runtime while preserving the original functionality.
    codeflash-ai[bot] authored Nov 22, 2024
    Copy the full SHA
    ac02db0 View commit details

Commits on Dec 12, 2024

  1. Merge pull request #5 from codeflash-ai/codeflash/optimize-_init-2024…

    …-11-22T07.08.24
    
    ⚡️ Speed up function `_init` by 11% in `src/requests/status_codes.py`
    Saga4 authored Dec 12, 2024
    Copy the full SHA
    099ad53 View commit details
Showing with 4 additions and 9 deletions.
  1. +4 −9 src/requests/status_codes.py
13 changes: 4 additions & 9 deletions src/requests/status_codes.py
Original file line number Diff line number Diff line change
@@ -107,22 +107,17 @@


def _init():
doc_lines = []
for code, titles in _codes.items():
for title in titles:
setattr(codes, title, code)
if not title.startswith(("\\", "/")):
setattr(codes, title.upper(), code)

def doc(code):
names = ", ".join(f"``{n}``" for n in _codes[code])
return "* %d: %s" % (code, names)
doc_lines.append(f"* {code}: {', '.join(f'``{title}``' for title in titles)}")

global __doc__
__doc__ = (
__doc__ + "\n" + "\n".join(doc(code) for code in sorted(_codes))
if __doc__ is not None
else None
)
if __doc__ is not None:
__doc__ += "\n" + "\n".join(doc_lines)


_init()