Skip to content

Use typed dicts with closed=True in from_native #3661

@dangotbanned

Description

@dangotbanned

Tracking

Related

Description

In pyrefly==1.0.0, this minimized version of the from_native overloads reports inconsistent-overload on every one of them.
mypy and pyright are fine with them.

I was shown this example, which seems to not be covered by these tests. So at the very least that needs checking.

If we make some changes like this - a future version of pyrefly might yell less:

-class _AllowLazy(TypedDict, total=False):
-    eager_only: Literal[False]
-    series_only: Literal[False]
-    allow_series: bool | None
+if TYPE_CHECKING:
+    import typing_extensions as te
 
+    class _AllowLazy(te.TypedDict, total=False):
+        eager_only: Literal[False]
+        series_only: Literal[False]
+        allow_series: bool | None
 
-class AllowLazy(_AllowLazy, total=False):
-    pass_through: bool
+    class AllowLazy(_AllowLazy, total=False, closed=True):
+        pass_through: bool

But this change might require some runtime acrobats, because closed isn't available until (https://docs.python.org/3.15/whatsnew/3.15.html#whatsnew315-typeddict)

Tasks

  • Try to reproduce this example
  • Dive through mypy/pyright issues to see if this has been discussed
  • Track any related ty features from (Tracking: Adopt ty as an (additional) type checker #3409)
    • Was missing Unpack and @overload support was in progress when I wrote this
  • Make sure any TYPE_CHECKING tricks play nicely with mkdocstrings
  • Update the TypedDict defs
  • Profit?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions