-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Permit to disable cyclic-import when importing inside a function #850
Comments
I think the checker itself is working as intended - cyclic imports can be problematic even when they don't break right away (like when using from-imports instead, or on older Python versions - for example, 3.5 can handle some cyclic imports 3.4 can't). That being said, I disabled it myself too because it was too noisy. Then again, it only complaining when Python complains anyways would be somewhat pointless. Maybe as a middle ground, |
I think it makes sense not to emit the error in case one of the imports is inside a function scope, as @The-Compiler already said. Sometimes getting rid of cyclic imports is impossible, requiring redesigning the entire project (as we already have this problem in astroid for example). That being said, I'll probably work on a patch in this weekend, if no one else wants to do it. |
IMHO we should always warn about cyclic import and let the user explicitly
|
True, but at least they should have some control over disabling the error in a more granular way. My initial thought is to have a flag that can control if the users want to not warn about cyclic-import if one of the imports is protected by a function scope, defaulting to false, so with the same behaviour as now. |
another idea would be that "# disable: cyclic-import" would make the On Fri, Mar 18, 2016 at 7:13 PM, Claudiu Popa notifications@github.com
Sylvain |
Discussion looks like a duplicate of #59, with exception of function-scope imports. |
mb it could be two different warnings, |
@PCManticore Is this issue fixed? |
I think the suggestion from sthenault to break cycle on |
Fixing this would require a restructure and there is no simple way to workaround the error, even though this seems to be a legitimate use case of a cyclic import. I found some discussion in an open issue related to this at pylint-dev/pylint#850.
@Pierre-Sassoulas I think I can try to work on this but I don't think I understand this implementation suggestion. What does it mean to break cycle in this context? Maybe a test case would help. |
In the algorithm to detect cyclic import we follow the "cycle" of import (https://github.com/PyCQA/pylint/blob/2ae0e98454c28e2aaf1c892655f34eb8d19772d7/pylint/graph.py#L181), if at some point an import is done in a context where |
I'm trying to come up with a test case but I think the local disabling is actually working as intended? Try this: a.py
b.py
if b.py is updated to
The |
* feat: elementwise functions (mappers) * abs * acos, acosh * Give up on versioned submodules; it makes typing difficult. * Give up on versioned submodules; it makes typing difficult. * Give up on versioned submodules; it makes typing difficult. * Also checking function values. * atan, atan2, atanh, bitwise_and, bitwise_invert * bitwise_shift_left, bitwise_or, bitwise_shift_right, bitwise_xor, ceil * Use 'numpy.array_api' to test these functions. * conj, cos, cosh, divide, equal * exp, expm1, floor, floor_divide * greater, greater_equal, imag * isfinite, isinf, isnan, less, less_equal, log, log1p, log2, log10, logaddexp, logical_and, logical_not, logical_or, logical_xor * multiply, negative, not_equal, positive, pow, real, remainder, round * sign, sin, sinh, square, sqrt, subtract, tan, tanh, trunc; finished all of the free elementwise functions * Implemented all elementwise dunder methods on 'array', too. * pylint in CI is tripping up on pylint-dev/pylint#850. * Also test all of the in-place dunder methods.
If two modules import from each other, but one of them only imports the other within functions and other non-global scopes, Python is happy. But pylint still errors on such cyclic imports, and in fact won't accept a module-scoped disable directive, so cyclic import detection has to be disabled for the entire project.
Here's an example from this PR: certbot/certbot#2649 :
The text was updated successfully, but these errors were encountered: