- Saved searches
- Use saved searches to filter your results more quickly
- R504 false positive when variable is a function parameter #133
- R504 false positive when variable is a function parameter #133
- Comments
- Description
- Saved searches
- Use saved searches to filter your results more quickly
- False-Positive R504 in non-trivial if-else Block #132
- False-Positive R504 in non-trivial if-else Block #132
- Comments
- Description
- R504 unnecessary variable assignment before return statement как исправить
- Comments
- Description
- Saved searches
- Use saved searches to filter your results more quickly
- flake8-return wrongly indicates R504 #47
- flake8-return wrongly indicates R504 #47
- Comments
- Description
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
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
R504 false positive when variable is a function parameter #133
R504 false positive when variable is a function parameter #133
Comments
- Date you used flake8-return: 2023-03-16
- flake8-return version used, if any: 1.2.0
- Python version, if any: 3.10.9
- Operating System: Linux
Description
def foo(a): if . a = 2 return a
$ flake8 foo.py --select=R foo.py:4:12: R504 unnecessary variable assignment before return statement.
variables that are function parameters should not be treated as unnecessary, cursory skim of https://github.com/afonasev/flake8-return/blob/master/flake8_return/mixins/unnecessary_assign.py looks like it doesn’t look at FunctionDef or AsyncFunctionDef at all which explains it.
The text was updated successfully, but these errors were encountered:
Sure, it’s got typing issues too — but the code that inspired the above example was actually an attempt to get rid of R504 for a more complex case — where the underlying complexity is in class attribute modifications where adding a new variable doesn’t help:
class A: def foo(self, a): b = a if . b = function(self.class_var) self.class_var = None return b
this will also raise R504, and only way to get around that is with a different temporary variable (or even one per class variable you’re caring about, which quickly becomes a vastly inferior solution, or in my case modifying a lot of state with a method call).
class A: def foo(self, a): tmp_var = self.class_var self.class_var = None if . return function(tmp_var) return a
I’m much less sure about how to go about attempting to get rid of that false positive though.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
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
False-Positive R504 in non-trivial if-else Block #132
False-Positive R504 in non-trivial if-else Block #132
Comments
- Date you used flake8-return: 2023-02-11
- flake8-return version used, if any: 1.2.0
- Python version, if any: 3.10
- Operating System: Windows 11
Description
The application of R504 unnecessary variable assignment before return statement seems wrong here.
I’ve specifically not inlined my return statement in order to have a single return in this «complicated» if-else block.
def test(x: int) -> str: retval: str if x == 1: retval = "Hello" elif x == 2: # . complicated code where I prefer a single return statement at the end. retval = "World" else: retval = "There" return retval # < R504
The example on the homepage was for the trivial case of an unnecessary assignment, but for something more complicated like this I think it should not flag R504 anywhere in the method.
The text was updated successfully, but these errors were encountered:
R504 unnecessary variable assignment before return statement как исправить
Date you used flake8-return: 2020-06-18 flake8-return version used, if any: 1.1.1 Python version: 3.8.0 Operating System: Windows 10 Description flake8-return wrongly indicates R504 for the followi.
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
flake8-return wrongly indicates R504
Comments
- Date you used flake8-return: 2020-06-18
- flake8-return version used, if any: 1.1.1
- Python version: 3.8.0
- Operating System: Windows 10
Description
flake8-return wrongly indicates R504 for the following samples:
formatted = _USER_AGENT_FORMATTER.format(format_string, **values) # clean up after any blank components formatted = formatted.replace('()', '').replace(' ', ' ').strip() return formatted #
def user_agent_username(username=None): if not username: return '' username = username.replace(' ', '_') # Avoid spaces or %20. try: username.encode('ascii') # just test, but not actually use it except UnicodeEncodeError: username = quote(username.encode('utf-8')) else: # % is legal in the default $wgLegalTitleChars # This is so that ops know the real pywikibot will not # allow a useragent in the username to allow through a hand-coded # percent-encoded value. if '%' in username: username = quote(username) return username #
Thx for issue! I will try fix it.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
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
flake8-return wrongly indicates R504 #47
flake8-return wrongly indicates R504 #47
Comments
- Date you used flake8-return: 2020-06-18
- flake8-return version used, if any: 1.1.1
- Python version: 3.8.0
- Operating System: Windows 10
Description
flake8-return wrongly indicates R504 for the following samples:
formatted = _USER_AGENT_FORMATTER.format(format_string, **values) # clean up after any blank components formatted = formatted.replace('()', '').replace(' ', ' ').strip() return formatted #
def user_agent_username(username=None): if not username: return '' username = username.replace(' ', '_') # Avoid spaces or %20. try: username.encode('ascii') # just test, but not actually use it except UnicodeEncodeError: username = quote(username.encode('utf-8')) else: # % is legal in the default $wgLegalTitleChars # This is so that ops know the real pywikibot will not # allow a useragent in the username to allow through a hand-coded # percent-encoded value. if '%' in username: username = quote(username) return username #
The text was updated successfully, but these errors were encountered: