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

chore(mypy): enable truthy-bool error code #3824

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

Conversation

sobolevn
Copy link
Member

Docs: https://mypy.readthedocs.io/en/stable/error_code_list2.html#check-that-expression-is-not-implicitly-true-in-boolean-context-truthy-bool

I am using # type: ignore[truthy-bool] for .components check, because I see that it is treated specially for some reason (like pragma: no cover). Is this correct?

I also removed configs that are part of the --strict flag from settings.

@sobolevn sobolevn requested review from a team as code owners October 17, 2024 08:01
@github-actions github-actions bot added area/dependencies This PR involves changes to the dependencies area/private-api This PR involves changes to the privatized API size: small area/security pr/external Triage Required 🏥 This requires triage labels Oct 17, 2024
Copy link

codecov bot commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 98.41%. Comparing base (682e4c7) to head (f568548).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
litestar/security/base.py 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3824   +/-   ##
=======================================
  Coverage   98.41%   98.41%           
=======================================
  Files         332      332           
  Lines       15472    15472           
  Branches     1701     1701           
=======================================
  Hits        15226    15226           
  Misses        113      113           
  Partials      133      133           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

sonarcloud bot commented Oct 17, 2024

Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3824

@sobolevn
Copy link
Member Author

Please, take a look at these lines:
Снимок экрана 2024-10-17 в 11 43 46

Looks like else is never actually reached. Should I remove this branch?

@provinzkraut
Copy link
Member

Looks like else is never actually reached. Should I remove this branch?

Seems to be a missing test case?

@sobolevn
Copy link
Member Author

Seems to be a missing test case?

I am not quite sure, to be honest :)
Here's why. Here's the code in question:

if isinstance(app_config.openapi_config.components, list):
app_config.openapi_config.components.append(self.openapi_components)
elif app_config.openapi_config.components:
app_config.openapi_config.components = [self.openapi_components, app_config.openapi_config.components]
else:
app_config.openapi_config.components = [self.openapi_components]

Where app_config.openapi_config.components has a type of Components | list[Components]

components: Components | list[Components] = field(default_factory=Components)
Components can never be false (it does not have __bool__ or __len__ defined).

So, mypy raises an error for this case. We either have:

  • Missing None annotation for components and a missing test case ?
  • Extra else branch in this if ?

@provinzkraut
Copy link
Member

* Extra `else` branch in this `if` ?

Isn't it the elif branch that's extra then, and should be an else instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dependencies This PR involves changes to the dependencies area/private-api This PR involves changes to the privatized API area/security pr/external size: small Triage Required 🏥 This requires triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants