Skip to content

[1.20 regression] reachability in django-modern-rest #21132

Description

@sobolevn

Hi!

I am facing 150+ errors in my project https://github.com/wemake-services/django-modern-rest after updating mypy to 1.20 from 1.19.

Here are the most frequest ones:

lru_cache issues

dmr/response.py:236: error: Cannot determine type of "resolve_setting" [has-type]
dmr/response.py:236: note: Revealed type is "Any"
dmr/response.py:237: error: Cannot determine type of "resolve_setting" [has-type]
dmr/routing.py:108: error: Cannot determine type of "resolve_setting" [has-type]
dmr/routing.py:190: error: Cannot determine type of "resolve_setting" [has-type]
dmr/parsers.py:232: error: Cannot determine type of "resolve_setting" [has-type]
dmr/parsers.py:284: error: Cannot determine type of "resolve_setting" [has-type]

For some reason all code that is using resolve_setting fails with this error:

renderers_list= (
resolve_setting(Settings.renderers) ifrenderersisNoneelserenderers
)

Here's how it is defined:

@lru_cache(maxsize=MAX_CACHE_SIZE)defresolve_setting(
setting_name: Settings,
*,
import_string: bool=False,
) ->Any:
""" Resolves setting by *setting_name*. The result is cached using ``@lru_cache`` for performance. When testing with custom settings, you *must* call :func:`clear_settings_cache` before and after modifying Django settings to ensure the cache is invalidated properly. """setting=_resolve_defaults().get(
setting_name,
_DEFAULTS[setting_name],
)
ifimport_stringandisinstance(setting, str):
returnmodule_loading.import_string(setting)
returnsetting# pyright: ignore[reportUnknownVariableType]

Maybe @lru_cache(maxsize=MAX_CACHE_SIZE) is the root cause? If I remove this decorator - all errors are gone.

We also faced a similiar problem in our django-stubs PR: typeddjango/django-stubs#3252 (comment)

Unreachable

I have more than 120+ errors that some statements are unreachable.
Examples:

(.venv) ~/Desktop/django-modern-rest master ✗ 1 ⚠️
» mypy dmr
dmr/settings.py:122: error: Statement is unreachable [unreachable]
dmr/validation/settings.py:41: error: Statement is unreachable [unreachable]
  1. https://github.com/wemake-services/django-modern-rest/blob/9062072376962f8b9ba6e195244ca702fe3d15e8/dmr/settings.py#L122
  2. https://github.com/wemake-services/django-modern-rest/blob/9062072376962f8b9ba6e195244ca702fe3d15e8/dmr/validation/settings.py#L41

These are two different module-level definitions. Not sure what is the root cause here :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-reachabilityDetecting unreachable code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions