Skip to content

False positive on re.compile as attrs converter #5313

Open
@treuherz

Description

@treuherz

I've found what I think is a bug in mypy's attrs support.

# test.py
import re
import attr

@attr.s
class Test:
    foo = attr.ib(converter=re.compile)

test = Test("foo")
$ mypy test.py
test.py:8: error: Argument 1 to "Test" has incompatible type "str"; expected "Union[AnyStr, Pattern[AnyStr]]"

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions