Fix type signature for callables passed to Converter with takes_self=True#1382
Fix type signature for callables passed to Converter with takes_self=True#1382filbranden wants to merge 1 commit intopython-attrs:mainfrom
Conversation
|
So what exact issue are we trying to solve here? There's kind of no point in using a TypeVar if we're going to reference it only once - the usual use case is to link a type in the function parameters to a type in the function return value, or a type in the class to a type in a method. |
|
@Tinche see #1372, though the author looped back in and mentioned finding a workaround. But I think it's not unreasonable that a converter for a field in attrs class C would take an instance of class C as its argument. Indeed it would be better if we could link the TypeVar to the definition, but I'm not sure how to do that part, because that would involve taking the class in which a If you think the workaround in #1372 (taking an |
|
Closing, as per discussion using |
|
Thanks for the discussion tho! |
Summary
Fix type signature for callables passed to
Converterwithtakes_self=True, so that using the specific attrs class that contains the field with the converter is valid in the callable type signature.Fixes #1378.
Note that python/mypy#15736 still triggers mypy errors when passing a Converter instance as a
converter=kwarg to a field, so work around that using# type: ignore[misc]in test cases.Pull Request Check List
mainbranch – use a separate branch!.pyi).tests/typing_example.py.attr/__init__.pyi, they've also been re-imported inattrs/__init__.pyi..rstand.mdfiles is written using semantic newlines.changelog.d.