green-code-initiative / creedengo-python

Reduce the environmental footprint of your Python software programs
https://green-code-initiative.org/
GNU General Public License v3.0
7 stars 10 forks source link

EC4 - False positives with TypeVar #23

Open Horrih opened 7 months ago

Horrih commented 7 months ago

Describe the bug When using python's TypeVar mechanism for type annotations, EC4 code smell is triggered. This should not be considered a code smell since using it in global scope is the standard way.

To Reproduce Example straight from the python official documentation image

Expected behavior Do not flag this as an error

dedece35 commented 4 months ago

Hi @Horrih, thank you for the issue. What do you think about it @jhertout ?

dedece35 commented 1 month ago

Hi @Horrih, I try to reproduce the problem but without success.

Here is my tests.

TEST 1

using strictly your example => NO PROBLEM on local Unit test

from collections.abc import Sequence from typing import TypeVar

U = TypeVar('U')

def second(l: Sequence[U]) -> U: return l[1]`

TEST 2

with a new line added => there is a real problem as expected at the line with "#noncompliant"

from collections.abc import Sequence from typing import TypeVar

U = TypeVar('U')

def second(l: Sequence[U]) -> U: print(U) #Noncompliant return l[1]

Do you still have the problem ? Can you give me a screenshot of the problem, please ? Can you give me the version of SonarQube and the version of your installed python plugin, please ?