-
Notifications
You must be signed in to change notification settings - Fork 138
Closed
astral-sh/ruff
#19354Labels
typing semanticstyping-module features, spec compliance, etctyping-module features, spec compliance, etc
Description
would like ty to allow literal instantiation of TypedDict's, as in:
class Config(typing.TypedDict):
version: str
tracked_tables: list[TrackedTable]
def get_default_config() -> absorb.Config:
# doesn't work
return {
'version': '0.1.0',
'tracked_tables': [],
}it gives this error:
error[invalid-return-type]: Return type does not match returned value
--> absorb/ops/config.py:12:29
|
12 | def get_default_config() -> Config:
| ------------- Expected `Config` because of return type
13 | return {
| ____________^
14 | | 'version': '0.1.0',
15 | | 'tracked_tables': [],
16 | | }
| |_____^ expected `Config`, found `dict[Unknown, Unknown]`
|
info: rule `invalid-return-type` is enabled by default
instead I had to convert many parts of my codebase to using this style to pass ty's checks:
def get_default_config() -> Config:
return Config(
version=absorb.__version__,
tracked_tables=[],
)this is undesirable because:
- one of the advantages of TypedDict's is being able to use them with normal simple dict syntax
- mypy (which I usually use) supports this style of TypedDict instance literals
- the two syntaxes are nearly functionally equivalent
mflova
Metadata
Metadata
Assignees
Labels
typing semanticstyping-module features, spec compliance, etctyping-module features, spec compliance, etc