python:S1192 String literals should not be duplicated - with Type hints (PEP 484)

Code example:


import httpx

async with httpx.AsyncClient() as client:
    r1: 'httpx.Response' = await client.get('')
    r2: 'httpx.Response' = await client.get('')
    r3: 'httpx.Response' = await client.get('')
    print(r1.status_code, r2.status_code, r3.status_code)

The code above is showing the code smell

python:S1192 String literals should not be duplicated

SonarQube Scanner
Java 11.0.3 AdoptOpenJDK (64-bit)
SonarQube Community Edition Version 8.2 (build 32929)

python v3.8.1
pytest version 5.3.4 (Your code has been rated at 10.00/10)

Hi @vorona,

Thank you for reporting this issue and welcome to the community. I confirm that we still have this issue on the last version of the python analyzer (which we just released).

Just to add a little more context. The interesting part of PEP 484 is:

Forward references
When a type hint contains names that have not been defined yet, that definition may be expressed as a string literal, to be resolved later.

Type annotations should not be reported as duplicate strings. Type checkers will raise an issue if the type hint has a typo, and putting these strings in a variable doesn’t help readability.

I created the following ticket: [SONARPY-665] - Jira


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.