Typing of `optional` validator fails
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
Research direction
Start by reproducing the two MdParserConfig examples with the provided mypy configuration. Inspect the typing of optional and deep_iterable validators and how their inferred types interact with attr.ib. Done means both the None default and the tuple default pass mypy type checking without an incompatible validator error.
Written by the indexing model from the issue text.
Description
Heya, minor issue with typing:
This passes mypy type checking:
@attr.s()
class MdParserConfig:
url_schemes: Optional[Iterable[str]] = attr.ib(
default=None,
validator=optional(deep_iterable(instance_of(str), instance_of((list, tuple)))),
)
but then weirdly changing the default to anything else fails, e.g.
@attr.s()
class MdParserConfig:
url_schemes: Optional[Iterable[str]] = attr.ib(
default=("http", "https"),
validator=optional(deep_iterable(instance_of(str), instance_of((list, tuple)))),
)
leads to:
error: Argument "validator" has incompatible type "Callable[[Any, Attribute[Union[List[Any], Tuple[Any, ...], None]], Union[List[Any], Tuple[Any, ...], None]], Any]"; expected "Union[Callable[[Any, Attribute[Tuple[str, str]], Tuple[str, str]], Any], Sequence[Callable[[Any, Attribute[Tuple[str, str]], Tuple[str, str]], Any]], None]" [arg-type]
for reference, this is my mypy configuration
[mypy]
show_error_codes = true
check_untyped_defs = true
strict_equality = true
no_implicit_optional = true
warn_unused_ignores = true
thanks in advance!
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-attrs/attrs
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-attrs/attrs#1620 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
python-attrs/attrs#1596 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1549 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
python-attrs/attrs#1543 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1532 ·
All issues in python-attrs/attrs
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
use-agent-os/agent-os#3314 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
BasedHardware/omi#15662 · 1 comment ·
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
AiursoftWeb/AnduinOS-2#19 ·