-
Notifications
You must be signed in to change notification settings - Fork 795
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
fix(typing): Ignore [arg-type]
error in _deduplicate_enum_errors
#3475
Conversation
…rors` Fixes `mypy` error that appeared during a merge vega#3467 (comment)
I'm fairly certain it is |
@Julian, quick question: is this something to expect to introduce in packages that are dependent on jsonschema? |
From a glance at the discussion, I think If |
Okay so I'm more confident this was caused by the stubs being updated (11 hours ago)
This does have the annotation: validator_value: Any | Unset Which
Whereas @mattijn I think the solution to avoiding regressions like this in the future, would be getting Looking through the projects they currently test in https://github.com/hauntsaninja/mypy_primer/blob/57a892bb6903a06dc7f5042018c0659caf760898/mypy_primer/projects.py#L61 - there are many smaller projects already included. |
The issue is not related to any runtime changes python-jsonschema/jsonschema#1019 (comment)
@mattijn really appreciate you questioning this in #3475 (comment) There were no runtime changes introduced by If the |
_deduplicate_enum_errors
[arg-type]
error in _deduplicate_enum_errors
I'm a bit concerned that this means that the latest released altair version will not pass mypy checks anymore when using the latest released version of jsonschema. Or I'm wrong in thinking this? Does this need to be raised at the typeshed repository? @binste, do you have some insights here, also on mypy_primer. I don't feel technically skilled in regards to type optimizations. |
@mattijn apologies if I've misunderstood the question, but to break this down:
|
v4.22.0 | v4.23.0 |
---|---|
class _Error(Exception):
def __init__(
self,
message: str,
validator=_unset,
path=(),
cause=None,
context=(),
validator_value=_unset, # <---------------------
instance=_unset,
schema=_unset,
schema_path=(),
parent=None,
type_checker=_unset,
) -> None: ... |
class _Error(Exception):
def __init__(
self,
message: str,
validator: str = _unset,
path: Iterable[str | int] = (),
cause: Exception | None = None,
context=(),
validator_value: Any = _unset, # <----------------------
instance: Any = _unset,
schema: Mapping[str, Any] | bool = _unset,
schema_path: Iterable[str | int] = (),
parent: _Error | None = None,
type_checker: _types.TypeChecker = _unset,
) -> None: ... |
typeshed
- The corresponding update to
typeshed.stubs.jsonschema
is not equivalent - To satisfy
mypy
as a result, you would need to check every parameter every time to confirm it is notUnset
- This is not something that the new release of
jsonschema
wanted to achieve, and is mentioned multiple times throughout the PR
v4.22.0 | v4.23.0 |
---|---|
class _Error(Exception):
def __init__(
self,
message: str,
validator: _utils.Unset | None | protocols.Validator = ...,
path: Sequence[str | int] = (),
cause: Incomplete | None = None,
context: Sequence[ValidationError] = (),
validator_value=..., # <--------------------
instance=...,
schema=...,
schema_path: Sequence[str | int] = (),
parent: _Error | None = None,
type_checker: _utils.Unset | TypeChecker = ...,
) -> None: ... |
class _Error(Exception):
def __init__(
self,
message: str,
validator: str | Unset = sentinel,
path: Iterable[str | int] = (),
cause: Exception | None = None,
context: Sequence[ValidationError] = (),
validator_value: Any | Unset = sentinel, # <--------------------
instance: Any | Unset = sentinel,
schema: Mapping[str, Any] | bool | Unset = sentinel,
schema_path: Iterable[str | int] = (),
parent: _Error | None = None,
type_checker: TypeChecker | Unset = sentinel,
) -> None: ... |
I'm a bit concerned that this means that the latest released altair version will not pass mypy checks anymore
Specifically on this point, altair
does pass mypy
checks on this branch.
To the same extent that any usage of # type: ignore can be considered passing mypy
.
Does this need to be raised at the
typeshed
repository?
I think so, but I'm unsure whether this would need to be raised by @Julian / @DanielNoord
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a joy to review PRs which are as well documented as this one! Thanks @dangotbanned for figuring out where the issue came from and explaining it, even with diffs :)
As Dan mentioned, mypy is happy if errors are ignored so that's fine + the error is due to a wrong type hint and not due to something that would cause issues at runtime -> Ignoring the error until type hints are fixed makes sense to me. Especially as Julian has mentioned that it's always str
despite the different type hints.
I'm not familiar with mypy_primer but if it's easy to get Altair added, I think it would be great if PRs in mypy get tested against Altair code (if I understand it correctly).
Thanks @binste I wasn't happy with my earlier uncertainty of what caused the issue, but it was an interesting trail to follow
I'd seen it mentioned before, but it was specifically this python/typeshed#12315 (comment) which I thought was worth mentioning. If I've understood correctly, this bot would've flagged the change in This issue hauntsaninja/mypy_primer#42 seems to be tracking projects to add |
Fixes
mypy
error that appeared during a merge https://github.com/vega/altair/actions/runs/9905108163/job/27364368641Edit
This is ready to merge and is blocking for all other PRs