| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
This will need changes in the spec text as well as the conformance suite, and it will need to be approved by the Typing Council. (Personally, I'm supportive of doing something like this, but haven't thought too much about the exact proposal yet.) |
Sorry, something went wrong.
|
@JelleZijlstra What do you have in mind? My problem is that the spec is currently not specific about this at all (see this discussion) and I haven't gotten much feedback on where people would want to take this in the same thread. Would you want to add something to the spec like this:
This is of course just my initial idea, any guidance is appreciated. The current spec doesn't really talk about this, so this should be more of an addition. |
Sorry, something went wrong.
|
Something like that, yes. If the spec doesn't currently discuss this, that means we should add it. The spec text shouldn't call out any specific type checker (like mypy). Instead, we should generically say that type checkers may use syntax like [code] to restrict the type ignore. |
Sorry, something went wrong.
|
I have pushed a new update to the spec. It's just a small addition and I hope it reflects the general sentiment of the discussion in the typing discuss. As always I'm happy to integrate feedback. |
Sorry, something went wrong.
|
@JelleZijlstra Would you mind looking at this spec change? I'd prefer at least a single opinion before I bring this to the typing council. |
Sorry, something went wrong.
|
I removed the parts where I tried to specify how whitespace after # type: ignore works. Now it's just about error codes. |
Sorry, something went wrong.
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Carl Meyer <carl@oddbird.net>
| # type: ignore # <comment or other marker> | ||
|
|
||
| The form ``# type: ignore[...]`` may be used to suppress only type errors with a | ||
| given error code, though support for this is optional and may vary by type checker: |
There was a problem hiding this comment.
What about also documenting that multiple error codes can be given (comma-separated), and unrecognized error codes should be ignored, if a type checker supports ignoring errors based on specific error code, as @ilevkivskyi suggested here.
Sorry, something went wrong.
There was a problem hiding this comment.
Are there any other opinions on this? I'm pretty open to changes here.
I personally think that the comma separated form doesn't need to be specified explicitly.
unrecognized error codes should be ignored, if a type checker supports ignoring errors based on specific error code
Does this mean that Mypy would need to ignore the error code "undefined"? Currently it adds errors at least when using --warn-unused-ignores: https://mypy-play.net/?mypy=latest&python=3.12&flags=warn-unused-ignores&gist=27ebc9511f193a9f348b0235412cbcc9
Sorry, something went wrong.
There was a problem hiding this comment.
I personally think that the approach outlined by @ilevkivskyi is the right one for multi-type-checker interoperability (much better than requiring totally separate ignore comments for each type checker), and I would be happy to fully specify it. But that would be a specification change that puts pyright and pyrefly out of conformance. If we did that, then I think the fulI behavior, including multiple comma separated codes, should be specified. I guess maybe we need feedback at least from pyrefly here: is the "always blanket ignore" behavior pyrefly's UX preference, or just something that was done to satisfy the previous conformance suite requirements?
But I think as long as the specification here is looser, as currently written (to accommodate both the pyright/pyrefly behavior and the mypy/zuban/ty behavior), it's not really important to document the multiple-error-codes handling, since effectively all this spec is now saying is that type checkers can do whatever they want with the information inside the brackets.
(Either way, I don't think the spec should _require_that type checkers be silent about unknown codes; it should be OK to warn users about them, as mypy does with --warn-unused-ignores. This is better behavior for users who aren't using multiple type checkers. Ideally users in multi-type-checker scenarios can turn off that warning if they don't want it.)
I'm happy with the current state of this PR as a first step, at least.
Sorry, something went wrong.
There was a problem hiding this comment.
I'm fine with the current wording in this PR.
As for @ilevkivskyi's suggestion - I personally like it, but I'd like to run this by some other pyrefly devs who have thought a lot more than I have about configuration and adoption, to make sure this isn't incompatible with our tooling in some way that I'm missing.
Sorry, something went wrong.
There was a problem hiding this comment.
As for @ilevkivskyi's suggestion - I personally like it, but I'd like to run this by some other pyrefly devs [...]
We discussed this and flagged a couple questions/concerns:
Sorry, something went wrong.
There was a problem hiding this comment.
We should probably move this to a Discuss thread if someone wants to champion actually specifying the multiple-codes-in-type-ignore approach. I think the issues raised by the Pyrefly team are definitely real ones.
Regarding the first, I would just say that it's already a minority of type errors where checkers vary on the reported line, so the proposal is still a strict improvement for the ~90+% where type checkers naturally agree (because there's no real ambiguity). So some effort to standardize more of course wouldn't hurt, but this doesn't seem like a blocker.
Regarding the second, what ty does is expect all our codes in # type: ignore[...] to be prefixed with ty:, so we can still flag/remove all unused definitely-for-ty ignores, which is on par with what we can do with # ty: ignore. Whether we should ever remove (or flag as unused) ignores which might apply to other type checkers, is I think a UX question for each type checker. Might be useful for single-type-checker users, but definitely not desirable for multi-type-checker users, so at best it would need to be configurable.
Sorry, something went wrong.
| # type: ignore # <comment or other marker> | ||
|
|
||
| The form ``# type: ignore[...]`` may be used to suppress only type errors with a | ||
| given error code, though support for this is optional and may vary by type checker: |
There was a problem hiding this comment.
I personally think that the approach outlined by @ilevkivskyi is the right one for multi-type-checker interoperability (much better than requiring totally separate ignore comments for each type checker), and I would be happy to fully specify it. But that would be a specification change that puts pyright and pyrefly out of conformance. If we did that, then I think the fulI behavior, including multiple comma separated codes, should be specified. I guess maybe we need feedback at least from pyrefly here: is the "always blanket ignore" behavior pyrefly's UX preference, or just something that was done to satisfy the previous conformance suite requirements?
But I think as long as the specification here is looser, as currently written (to accommodate both the pyright/pyrefly behavior and the mypy/zuban/ty behavior), it's not really important to document the multiple-error-codes handling, since effectively all this spec is now saying is that type checkers can do whatever they want with the information inside the brackets.
(Either way, I don't think the spec should _require_that type checkers be silent about unknown codes; it should be OK to warn users about them, as mypy does with --warn-unused-ignores. This is better behavior for users who aren't using multiple type checkers. Ideally users in multi-type-checker scenarios can turn off that warning if they don't want it.)
I'm happy with the current state of this PR as a first step, at least.
Sorry, something went wrong.
Co-authored-by: Carl Meyer <carl@oddbird.net>
I'd also be happy to add that to the spec. I think if we want to do that we should ask for feedback on Discuss again, because people like @jorenham (scipy-stubs maintainer) might want to weigh in there for these multi-typechecker scenarios. |
Sorry, something went wrong.
I don't have any particular preference to be honest. Anything that'll allow me to simplify things like # NOTE: These raise a `ValueError` if passed anything other than `ClusterNode`
@override
# pyrefly: ignore [bad-override]
def __eq__(self, node: ClusterNode, /) -> bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] # ty: ignore[invalid-method-override](src), and I'll be happy. |
Sorry, something went wrong.
FWIW since we already changed ty's behaviour here, I believe you can already simplify it slightly to # NOTE: These raise a `ValueError` if passed anything other than `ClusterNode`
@override
# pyrefly: ignore [bad-override]
def __eq__(self, node: ClusterNode, /) -> bool: ... # type: ignore[override, ty:invalid-method-override] # pyright: ignore[reportIncompatibleMethodOverride] |
Sorry, something went wrong.
|
I'm not really sure how you handle situations like this, do I merge now that everyone has ticked off the box? I understand that the discussion around standardizing # type ignore[<content>] is still going on (where <content> could be defined as a comma separated list with namespaces and such). I'm supportive of that change, but I would prefer to merge this one first. |
Sorry, something went wrong.
|
@davidhalter I think once you have five checkmarks on the typing-council issue and at least one approving review on the PR, you are good to merge. |
Sorry, something went wrong.
This unfortunately will cause mypy to complain: Unused "type: ignore[ty:invalid-method-override]" comment |
Sorry, something went wrong.
This is a bug (or at least something that we want to change) in mypy. |
Sorry, something went wrong.
|
It seems like merging this PR (even though it was green) broke the CI pipeline on main. @JelleZijlstra Would you have time to look at this. It feels like a weird issue with Pyright when they do new releases: https://github.com/python/typing/actions/runs/24907018988/job/72938873294 I can try to fix this, but I don't have that much time until Monday. And you seem to have implemented these checks in the CI. (Not blaming you here at all, thanks for your work!) |
Sorry, something went wrong.
|
That's a fun one! We probably should have a post-processing step to remove such errors. |
Sorry, something went wrong.
* main: Docs: Fix typo and grammar in type narrowing guide (python#2271) Update ty results for v0.0.35 (python#2282) Add pycroscope to the conformance suite (python#2278) Bump type checkers (python#2279) Update ty results for v0.0.33 (python#2275) conformance: allow consistent treatment of kwargs: Unpack[TD] (python#2272) bump mypy and pyright (python#2274) fix pyright version parsing (python#2273) Allow type checkers to ignore specific error codes (python#2153) Update pyrefly conformance results to v0.62.0 (python#2269) add ty to scripts/bump_type_checkers.py (python#2268)
| Back | FazBrowse Home | New Git URL |
Changes the error code from additional_stuff to assignment (as Mypy uses it).
This was the proposal Rebecca: