Comments (10)
We actually now have code that attempts to traverse as much of the class hierarchy as is possible (given the AST's limitations). We use it to find Exception
subclasses.
pep8-naming/src/pep8ext_naming.py
Lines 300 to 316 in 9adbbc4
A path to implementing the suggestion in this issue might be:
- Generalize the code above
- Introduce an
ignore-class-names
(or similar) configuration option which skips all (or a subset of?) checks for matching subclasses - Consider defaulting the list of ignored class names to
["TypedDict"]
from pep8-naming.
I wasn't thinking to cover 100% of the cases but feels like covering the most common case (direct inheritance) as a low hanging fruit with a big benefit. It's fine e.g. to say we don't support typed dict definitions across files.
from pep8-naming.
We don't special case anything like this except what we default --ignore-names
to. That would likely be the best place to configure this.
from pep8-naming.
I don't consider it a viable option, clearly, in this case, the PEP shouldn't mandate, and I don't think having to allowlist every name one by one is the path ahead. Also, I don't want these names to show up outside of a typed dictionary. So let us reconsider please.
from pep8-naming.
We would need significant refactoring to say "Ah, this has inherited umpteen times from a TypedDict and yes it's that TypedDict" which to handle 1 attribute here isn't reasonable. If we had anything like that, the unittest
methods that are part of the default --ignore-names
wouldn't be there but would be part of an exclusion applied to any class that inherits from unittest.TestCase
.
The part where this becomes especially difficult is where we don't execute code we statically analyze it, so if someone inherits from some 3rd party library class that inherits from TypedDict
, we aren't going to be able to detect that. We don't follow imports today, we don't want to (it adds significant time, fragility, and complexity - see also openstack's "hacking" plugin), and we'd still end up with issues like this.
from pep8-naming.
Since TypedDict
is a special case, and this is much simpler to implement than adding a new option, I've raised #189 as a proposal to address that specific case
from pep8-naming.
--ignore-class-names
fixes the problem of wanting to understand inheritance across modules, @danielpatrickdotdev, because we can't handle that otherwise as you rediscovered in #189.
from pep8-naming.
--ignore-class-names
fixes the problem of wanting to understand inheritance across modules, @danielpatrickdotdev, because we can't handle that otherwise as you rediscovered in #189.
It does, but I'm never keen on blanket ignores like that, so was hoping for something more precise. I can live with something that covers common cases though
from pep8-naming.
Having a list of class names is far more precise than blanket ignoring any TypedDict inherited class which may or may not have non-snake-case attributes.
from pep8-naming.
In some ways it is, but it's quite an unweildy thing to define. I certainly wouldn't want to ignore all checks for a list of classes. Plus in this case we're interested in superclass names. I ended up with --ignore-variable-names-for-subclasses
. Even that mouthful doesn't quite capture it.
from pep8-naming.
Related Issues (20)
- Broken test with flake8>=3.9.1 HOT 6
- RecursionError when checking class that inherits from same-named class
- Warning instance attributes that are not camel_case compliant
- Renaming default branch to main HOT 1
- Drop dependency on flake8-polyfill HOT 2
- N815 is not being reported HOT 4
- N815 is not being reported HOT 1
- N816 does not make sense HOT 1
- False positive for N805 in a child class HOT 3
- False positive for HTTP request handler do_METHOD methods HOT 1
- False Error N805 HOT 1
- "camelcase imported as lowercase" failure in an import of a package or module HOT 12
- Add flake8_polyfill as requirement HOT 2
- Deprecation warning for options HOT 1
- Detect @classproperty mtehods as class methods HOT 3
- Feature request: ignore `N802` for methods marked with `@override` HOT 1
- Add naming rule for instance variables HOT 2
- ignore-names globbing is not case-sensitive on Windows HOT 1
- Add option to ignore N812 for specific packages
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 pep8-naming.