Closed Avasam closed 6 months ago
yep! Would accept a fix here! I hadn't seen this lint error before. Is it relatively new?
I am curious why this line https://github.com/nipunn1313/mypy-protobuf/blob/7506de3f39469e1a6665f1bf388f506a40571996/test/generated/testproto/test3_pb2.pyi#L209
does not cause this lint to fire? It seems like it should also cause the lint to fire - and we would have caught that.
I hadn't seen this lint error before. Is it relatively new?
It's existence in Flake8-pyi not new and has been enabled by default in early 2022: https://github.com/PyCQA/flake8-pyi/pull/101 It's been added to Ruff inv0.0.279 last year https://github.com/astral-sh/ruff/pull/5844
If you mean that it is raised in typeshed, also not new (same timeline as mentioned above), Y026
is just currently disabled in _pb2.pyi
files (as with other non-autofixable lint issues for autogenerated files)[^1]
After bumping mypy-protobuf to v3.6.0 in typeshed I just noticed that in typeshed's usage, that was the last violation of that rule left.
I am curious why this line [...] does not cause this lint to fire? It seems like it should also cause the lint to fire - and we would have caught that.
This should hopefully answer that question: https://github.com/PyCQA/flake8-pyi/blob/f60d7e3cdc833dd358b493d2ca80fd187cc38cfb/pyi.py#L1202-L1216
[^1]: Ruff supports autofixes for PYI026, but I believe typeshed is waiting on https://github.com/python/mypy/issues/16581 or https://github.com/plinss/flake8-noqa/pull/30 to avoid conflicting error codes.
this seems relevant
The only exceptions are the type aliases `X = (typing.)Any`
(special-cased, because it is so common in a stub),
and `X = None` (special-cased because it is so special).
I would argue that its actually false-positive in https://github.com/python/typeshed/blob/7d56cd9a6cf6e0a4ea89c68d0397e197aff32cbe/stubs/protobuf/google/protobuf/any_pb2.pyi#L177 - since that Any
is not typing.Any
, but rather a class Any
.
But in any case, we can still aim to fix. Adding a TypeAlias
annotation seems wholly reasonable.
[...] - since that
Any
is nottyping.Any
, but rather a classAny
.
You're right, I didn't look further to see it's not typing.Any
. I guess the question is then, are global___*
meant to be Type Alias or Variable Alias (you seem to be saying they should be type aliases anyway).
# global prefix globals are generated, but aren't used at runtime ._pb2.global___.
Output Format [...]
- Only mangle-alias top-level identifiers w/
global___
to avoid conflict w/ fields of same name [previously was mangling inner messages as well]
https://github.com/nipunn1313/mypy-protobuf/pull/321 added the
TypeAlias
annotation forclass.V
, but using stubs generated by typeshed, there's still a singleY026
(https://github.com/PyCQA/flake8-pyi/blob/main/ERRORCODES.md / https://docs.astral.sh/ruff/rules/type-alias-without-annotation/) violation in https://github.com/python/typeshed/blob/7d56cd9a6cf6e0a4ea89c68d0397e197aff32cbe/stubs/protobuf/google/protobuf/any_pb2.pyi#L177