Comments (9)
Thanks for asking.
how would you name this new message ?
I wonder that there still is an assigning-non-slot. Regarding that existing name I would suggest using declare-non-slot
(or define-non-slot
). I can't diffrenciate between declare and define.
For the docs and based on assigning-non-slot
:
Problematic code
class Student:
__slots__ = ("name",)
name: str
surname: str # [define-non-slot]
Correct code:
class Student:
__slots__ = ("name", "surname")
name: str
surname: str
from pylint.
Hey @adamtuft, thanks a lot for working on this ! Do you mind opening a pull request directly from your branch ? (Use "Refs #9499" in the description :) )
from pylint.
Thank you for opening the issue, how would you name this new message ?
There is already some slot related messages in the classe checker (https://github.com/pylint-dev/pylint/blob/main/pylint/checkers/classes/class_checker.py#L665), but it seems it could go in the data classes checker (https://github.com/pylint-dev/pylint/blob/main/pylint/checkers/dataclass_checker.py)
from pylint.
Hi there! I'm looking for a way to contribute and I'd like to try implementing this feature.
As well as the [define-non-slot]
case I can see another case that you might want to warn on:
Problematic code:
class Student:
__slots__ = ("name", "age") # [missing-slot-annotation]
name: str
Correct code:
class Student:
__slots__ = ("name", "age")
name: str
age: int
I'd consider this merely a warning rather than an error as this code will still run with the dataclass
decorator, whereas it won't in the [define-non-slot]
case.
These checks shouldn't be evaluated if __slots__
contains __dict__
.
from pylint.
Sounds like a useful warning to me!
from pylint.
I have an implementation for declare-non-slot
at https://github.com/adamtuft/pylint/tree/9499-slots-and-class-annotations, would be very grateful for comments & discussion! I will also implement missing-slot-annotation
when I have a little more time.
A few points:
- I thought this check belonged in the class checker instead of the dataclass checker since the problematic code is problematic even without the dataclass decorator. There may be other cases where the class annotations and
__slots__
items should match, and making this check dataclass-specific would miss those cases. - I went with
declare-non-slot
overdefine-non-slot
as annotating a class feels more like a declaration that such a member exists, rather than a definition of that member. - I made some changes to existing code to factor out some logic into a helper function
_get_classdef_slots_names
as this seemed the cleanest way to re-use existing logic. I hope this is ok. - I've checked that the existing tests still pass and have run the primer tests with
python3 -m pytest -m primer_stdlib --primer-stdlib
.
from pylint.
@adamtuft do you think this can be closed following the merge of the new checker ?
from pylint.
@adamtuft do you think this can be closed following the merge of the new checker ?
The new checker covers the original issue, but there was also some discussion above of a missing-slot-annotation
warning. Would you still want this? It could be implemented later, referencing this (closed) issue.
from pylint.
Let's keep open for discussion about missing-slot-annotation
then. I'm +1 myself.
from pylint.
Related Issues (20)
- Gracefully handle invalid ‘ignore-paths’ regex crash HOT 4
- Infinite recursion of Pyreverse when numpy.array is in class HOT 1
- False positive on PEP695 generic class syntax HOT 1
- False positive invalid-sequence-index using properties of range object as index
- [Feature] new lint rule to require a comment #. at end each python block. HOT 7
- [Feature Request] new lint rule to require a comment #. (HashtagDot) (or #/, new line) at end each python block. And new lint rule for declaring variables to have #declare or #var comment. HOT 5
- Dublicate code wrong behavor. HOT 1
- Can't update functional test refs HOT 5
- False positive E0601: used-before-assignment in try and while block
- [Feature] new lint rule to require "new line" at end each code block. HOT 1
- Pylint does not discover a NoReturn method in certain cases to avoid "inconsistent-return-statements" HOT 3
- False positive for `use-yield-from` for generators yielding from iterators
- pylint crashing with `concurrent.futures.process.BrokenProcessPool` HOT 3
- E0606: detect validation done in external function HOT 6
- Crash ``Building error when trying to create ast representation of module 'aws_cp.__init__'`` HOT 1
- Crash ``Building error when trying to create ast representation of module 'aws_cp.aws'``
- Crash ``Building error when trying to create ast representation of module 'aws_cp.app'``
- pylint cannot find third-party packages in virtual environment HOT 3
- False Positive W0143-comparison-with-callable when using derived property descriptors
- Documentation about `class-const` needs to be updated.
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 pylint.