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

Merged
merged 2 commits into from
Nov 2, 2024
Merged

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

All modified and coverable lines are covered by tests ✅

Project coverage is 98.44%. Comparing base (ed35b61) to head (f9b187d).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3824      +/-   ##
==========================================
+ Coverage   98.42%   98.44%   +0.01%     
==========================================
  Files         333      333              
  Lines       15348    15346       -2     
  Branches     1694     1693       -1     
==========================================
  Hits        15107    15107              
+ Misses        111      110       -1     
+ Partials      130      129       -1     

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

@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?

@provinzkraut provinzkraut enabled auto-merge (squash) November 2, 2024 09:51
@provinzkraut provinzkraut merged commit c354e36 into main Nov 2, 2024
24 checks passed
@provinzkraut provinzkraut deleted the mypy-truthy-bool branch November 2, 2024 09:56
Copy link

sonarqubecloud bot commented Nov 2, 2024

Copy link

github-actions bot commented Nov 2, 2024

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

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 pr/internal size: small Triage Required 🏥 This requires triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants