Comments (5)
The trouble with this check is that flake8 produces undefined name errors if you use a name defined with just x: T
elsewhere in the stub. That's correct in general but causes some false positives in typeshed.
Two possible solutions:
- Track in flake8-pyi whether a name has been used elsewhere in the stub, and emit an error only when it's not used elsewhere. The machinery @AlexWaygood added for detecting unused typevars could be reused for this.
- Somehow teach flake8 to not emit errors in this case. This allows us to always remove
= ...
, which is more consistent. One approach could be to disable the standard flake8 undefined name error and add our own.
from flake8-pyi.
Following #364, flake8-with-flake8-pyi-installed no longer emits errors for this code:
x: int
y = x
That means we can now revisit this issue.
from flake8-pyi.
I just saw astral-sh/ruff#8818 and I've been wondering, should this apply to enums? Given they can be dynamically generated. Maybe that's not a use-case we'd want to support.
I don't see any particular reason that this hypothetical check should exclude enums — the following two enums in a stub file should (I think) be interpreted the same way by a type checker, but the second one is more explicit:
from _typeshed import Incomplete
class Foo(Enum):
X = ...
Y = ...
class Bar(Enum):
X: Incomplete
Y: Incomplete
If code generators are currently generating Foo, instead of Bar, we should fix the code generators ;)
That said, I think the ruff maintainers are correct to say in astral-sh/ruff#8818 that PIE796 probably shouldn't emit an error on Foo
in a stub file.
from flake8-pyi.
I just saw astral-sh/ruff#8818 and I've been wondering, should this apply to enums? Given they can be dynamically generated. Maybe that's not a use-case we'd want to support.
from flake8-pyi.
I thought it was completely breaking type-safety (at least in pyright), but I just forgot to write it in a .pyi
file, not .py
(since in a .py
file the vlaue needs to be initialized X: Any = ...
)
Not a problematic edge-case then.
from flake8-pyi.
Related Issues (20)
- Should we flag "unused" PEP-695 TypeVars? HOT 3
- Flag forbidden imports on the line they occur (after dropping support for Python 3.9)
- Detect redundant unions with buffer/bytes types? HOT 3
- Rule: Prefer `Iterator` over simple `Generator` for `__iter__` return type
- Standardizing Union of `Literal` and `None` HOT 7
- Detect nested `Literal` HOT 3
- Ensure `Generic` is always the last base class
- Detect redundant `Generic` in a class's bases? HOT 1
- Arguments to protocol methods should never be positional-or-keyword HOT 1
- Y053 should allow long strings as argument to `@deprecated`
- Disallow old-style positional only args (starting with double underscore) HOT 3
- Y019 sensitive to PEP 570 syntax
- Support flake8==7.0.0 HOT 3
- Warn for IO types like io.BytesIO HOT 4
- [Stylistic] Enforce a space after `# pyright:`, `# mypy:` and `# noqa:` comments HOT 5
- Final literals HOT 3
- text
- Warn about redundant `Incomplete` annotations HOT 1
- Y090 false positive for PEP-646
- Implement typeshed's if/else `sys.version_info` order of new vs old block
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flake8-pyi.