Skip to content

♻️ Move duplicated code portion to a static method in the APIKeyBase super class#3142

Merged
tiangolo merged 8 commits intofastapi:masterfrom
ShahriyarR:apikey-duplicated-code-refactoring
Jan 30, 2025
Merged

♻️ Move duplicated code portion to a static method in the APIKeyBase super class#3142
tiangolo merged 8 commits intofastapi:masterfrom
ShahriyarR:apikey-duplicated-code-refactoring

Conversation

@ShahriyarR
Copy link
Copy Markdown
Contributor

The code block below was used 3 times:

        if not api_key:
            if auto_error:
                raise HTTPException(
                    status_code=HTTP_403_FORBIDDEN, detail="Not authenticated"
                )
            else:
                return None
        return api_key

I have moved this portion to the staticmethod into the super class as it will be shared by inheritance to all 3 subclasses.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2021

Comment thread fastapi/security/api_key.py Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2022

Codecov Report

Merging #3142 (8ce0578) into master (ce0ec06) will not change coverage.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##            master     #3142     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files          243       531    +288     
  Lines         7419     13623   +6204     
===========================================
+ Hits          7419     13623   +6204     
Impacted Files Coverage Δ
fastapi/security/api_key.py 100.00% <100.00%> (ø)
fastapi/params.py 100.00% <0.00%> (ø)
fastapi/routing.py 100.00% <0.00%> (ø)
fastapi/encoders.py 100.00% <0.00%> (ø)
fastapi/responses.py 100.00% <0.00%> (ø)
fastapi/exceptions.py 100.00% <0.00%> (ø)
fastapi/concurrency.py 100.00% <0.00%> (ø)
fastapi/applications.py 100.00% <0.00%> (ø)
fastapi/openapi/docs.py 100.00% <0.00%> (ø)
tests/test_ws_router.py 100.00% <0.00%> (ø)
... and 318 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2252837...8ce0578. Read the comment docs.

@github-actions
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor

@patrick91 patrick91 left a comment

Choose a reason for hiding this comment

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

Nice!

@svlandeg
Copy link
Copy Markdown
Member

svlandeg commented Aug 14, 2024

@patrick91 : could you have another look at this PR, as it's not succeeding the linting step? 🙏

[Update]: I've gone in and fixed it 😉

@svlandeg svlandeg self-assigned this Sep 3, 2024
@svlandeg svlandeg changed the title Moved duplicated code portion to the staticmethod in the super class ♻️ Move duplicated code portion to a static method in the APIKeyBase super class Sep 3, 2024
@svlandeg svlandeg removed their assignment Sep 3, 2024
Copy link
Copy Markdown
Member

@tiangolo tiangolo left a comment

Choose a reason for hiding this comment

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

Nice, thank you! 🚀

And thanks for the reviews and help! ☕

@tiangolo tiangolo merged commit 30b270b into fastapi:master Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants