melevir / flake8-functions-names Goto Github PK
View Code? Open in Web Editor NEWAn extension for flake8 that validates functions names, decomposition and conformity with annotations.
License: MIT License
An extension for flake8 that validates functions names, decomposition and conformity with annotations.
License: MIT License
Magic/dunder methods such as __exit__(self, exc_type, exc_val, exc_tb) -> bool
and __contains__(self, x) -> bool
raise a FNE005 that is impossible to fix, and I don't want to add #noqa lines to these methods.
... even if it also has a pure word. For example, test_root_category_create
should not require pureness.
from typing import TextIO
from overrides import overrides
class MyTextIO(TextIO):
...
@overrides
def writable(self) -> bool:
return True
It would be very cool if there was an option to ignore overridden methods. There isn't much I can do about the names given to 3rd party interface methods, let alone Python stdlib.
For now, it will fail to give representation to a decorator like @foo.bar.baz
, for example.
The validator should fail in such cases.
Small code example:
def __eq__(self, other: Any) -> bool:
return str(self) == str(other)
The plugin reports FNE005 Return type of the function is bool, but the name doesn't show it
.
Since these are built-in methods, there's no way to rename them. I think in such cases this error shouldn't be reported. Applies also to other methods like __lt__()
, __contains__()
etc.
Exceptions seem like a problem since pure functions can't raise exceptions, but most functions with data-processing verbs can.
We need a decent resolution for the problem.
Perhaps adding a rule to validate that async functions have some naming convention will be useful. For example have a*
prefix. This way the caller can always determine if the function is async or not just by the name
FNE005 Return type of the function is bool, but the name doesn't shows it
class User:
@property
def profile_picture(self):
return "img.jpg"
Right now the above gives the error: FNE002 The method has a @property decorator, but has a verb in it's name (profile) [flake8-functions-names]
- which I think is not really warranted in this case.
I mean it is easy enough to disable for specific cases, but would it make sense to remove such words that can act as both nouns and verbs from the list? Or was it a deliberate decision anyways to include such examples as well?
I am using python 3.10 and my TypeGuard
functions are triggering FNE001. Here's an example that fails:
from typing import TypeGuard
class Point:
x: int
y: int
class NEQuadrantPoint(Point):
pass
def is_ne_quadrant(pnt: Point) -> TypeGuard[NEQuadrantPoint]:
return pnt.x > 0 and pnt.y > 0
@pytest.fixture
async def is_endpoint_raises_500_factory(client, webhooks_payload_factory):
async def is_endpoint_raises_500(route, payload_kwargs):
payload = webhooks_payload_factory(**payload_kwargs)
resp = await client.post(route, json=payload)
return resp.status == 500
return is_endpoint_raises_500
Gives double FNE001 error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.