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

[red-knot] Update tests for attributes inferred from parameters #16208

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions crates/red_knot_python_semantic/resources/mdtest/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ reveal_type(c_instance.inferred_from_value) # revealed: Unknown | Literal[1, "a
# TODO: Same here. This should be `Unknown | Literal[1, "a"]`
reveal_type(c_instance.inferred_from_other_attribute) # revealed: Unknown

# TODO: should be `int | None`
# There is no special handling of attributes that are (directly) assigned to a declared parameter,
# which means we union with `Unknown` here, since the attribute itself is not declared. This is
# something that we might want to change in the future.
#
# See https://github.com/astral-sh/ruff/issues/15960 for a related discussion.
reveal_type(c_instance.inferred_from_param) # revealed: Unknown | int | None

reveal_type(c_instance.declared_only) # revealed: bytes
Expand All @@ -45,10 +49,10 @@ reveal_type(c_instance.possibly_undeclared_unbound) # revealed: str
c_instance.inferred_from_value = "value set on instance"

# This assignment is also fine:
c_instance.inferred_from_param = None
c_instance.declared_and_bound = False

# TODO: this should be an error (incompatible types in assignment)
c_instance.inferred_from_param = "incompatible"
# error: [invalid-assignment] "Object of type `Literal["incompatible"]` is not assignable to attribute `declared_and_bound` of type `bool`"
c_instance.declared_and_bound = "incompatible"

# TODO: we already show an error here but the message might be improved?
# mypy shows no error here, but pyright raises "reportAttributeAccessIssue"
Expand Down Expand Up @@ -181,7 +185,6 @@ reveal_type(c_instance.inferred_from_value) # revealed: Unknown | Literal[1, "a
# TODO: Should be `Unknown | Literal[1, "a"]`
reveal_type(c_instance.inferred_from_other_attribute) # revealed: Unknown

# TODO: Should be `int | None`
reveal_type(c_instance.inferred_from_param) # revealed: Unknown | int | None

reveal_type(c_instance.declared_only) # revealed: bytes
Expand Down
Loading