-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
False positive on re.compile as attrs converter #5313
Labels
bug
mypy got something wrong
false-positive
mypy gave an error on correct code
priority-1-normal
topic-attrs
topic-type-variables
Comments
Yes, this is a bug in mypy attrs plugin. We need to be more careful when a converter is generic. |
ilevkivskyi
added
bug
mypy got something wrong
priority-1-normal
false-positive
mypy gave an error on correct code
labels
Jul 4, 2018
Just ran into this problem. Thanks for reporting! |
Ran into this as well. Same context. Simplest workaround is defining a method like the following as a thin wrapper: def compile_pattern(s: Union[str, bytes]) -> re.Pattern:
return re.compile(s)
@attr.s
class Matcher:
pattern: re.Pattern = attr.ib(converter=compile_pattern) |
Having the same issue, it seems to apply to import datetime as dt
from typing import TypeVar
import attr
import pandas as pd
DatetimeLike = TypeVar("DatetimeLike", dt.datetime, pd.DatetimeIndex)
def to_utc(t: DatetimeLike) -> DatetimeLike:
... # this function is used on both types of objects
@attr.s(auto_attribs=True, frozen=True)
class Foo:
bar: dt.datetime = attr.ib(converter=to_utc)
Foo(dt.datetime(...)) Running mypy on the above raises:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
mypy got something wrong
false-positive
mypy gave an error on correct code
priority-1-normal
topic-attrs
topic-type-variables
I've found what I think is a bug in mypy's attrs support.
Unless I've completely misunderstood what
AnyStr
is for, I don't think that signature should throw on receiving a string.I can't quite figure out if attrs or mypy is at fault here, but I can't get the same error to appear on
re.compile
when it's not being applied as a converter by attrs. Apologies if I've missed an obvious issue here.Python v3.6.5
Mypy v0.610
Attrs v18.1.0
The text was updated successfully, but these errors were encountered: