10000 Add signature for attr.evolve by ikonst · Pull Request #14526 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Add signature for attr.evolve #14526

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

Merged
merged 21 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
hmpf
  • Loading branch information
ikonst committed Jan 26, 2023
commit c1455145f31ec3272481a802d2086707dcb5e35a
7 changes: 6 additions & 1 deletion mypy/plugins/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,12 @@ def evolve_callback(ctx: mypy.plugin.FunctionSigContext) -> FunctionLike:
if len(ctx.args[0]) < 1:
return ctx.default_signature

node = ctx.args[0][0].node
expr = ctx.args[0][0]
if not isinstance(expr, RefExpr):
# TODO: can't rely on expressions having a type!
return ctx.default_signature

node = expr.node
if node is None:
return ctx.default_signature

Expand Down
5 changes: 4 additions & 1 deletion test-data/unit/check-attr.test
Original file line number Diff line number Diff line change
Expand Up @@ -1875,12 +1875,15 @@ import attr
class C:
name: str

def q() -> C:
return C(name='foo')

c = C(name='foo')
attr.evolve() # E: Missing positional argument "inst" in call to "evolve"
attr.evolve(c)
attr.evolve(c, name='bar')
attr.evolve(
c,
q(),
name=42, # E: Argument "name" to "evolve" has incompatible type "int"; expected "str"
)
attr.evolve(
Expand Down
0