Skip to content
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

EC4 - False positives with TypeVar #23

Open
Horrih opened this issue Apr 5, 2024 · 2 comments
Open

EC4 - False positives with TypeVar #23

Horrih opened this issue Apr 5, 2024 · 2 comments
Assignees
Labels
🗃️ rule rule improvment or rule development or bug 🚀 enhancement New feature or request 👀 👀 waiting commiter 👀 👀

Comments

@Horrih
Copy link

Horrih commented Apr 5, 2024

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
Copy link
Member

dedece35 commented Jul 27, 2024

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

@dedece35
Copy link
Member

dedece35 commented Oct 4, 2024

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 ?

@dedece35 dedece35 self-assigned this Oct 4, 2024
@dedece35 dedece35 added 🗃️ rule rule improvment or rule development or bug 🚀 enhancement New feature or request 👀 👀 waiting commiter 👀 👀 labels Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗃️ rule rule improvment or rule development or bug 🚀 enhancement New feature or request 👀 👀 waiting commiter 👀 👀
Projects
None yet
Development

No branches or pull requests

2 participants