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

Pylint 3.3.0 does not recognize f-string as string and reports no-member for startswith() #9947

Closed
andy-maier opened this issue Sep 22, 2024 · 5 comments · Fixed by #9951
Closed
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs astroid update Needs an astroid update (probably a release too) before being mergable Regression
Milestone

Comments

@andy-maier
Copy link

andy-maier commented Sep 22, 2024

Bug description

The following file test_pylint.py:

#!/usr/bin/env python
"""module"""


class Cls:
    # pylint: disable=too-few-public-methods
    """Cls"""


c_obj = Cls()

c_repr1 = '{!r}'.format(c_obj)  # pylint: disable=consider-using-f-string
c_repr2 = f'{c_obj!r}'

assert c_repr1.startswith('<__main__.Cls')
assert c_repr2.startswith('<__main__.Cls')  # pylint reports no-member

causes pylint to report this issue:

$ pylint test_pylint.py 
************* Module tmp_issues.test_pylint
test_pylint.py:16:7: E1101: Instance of 'Cls' has no 'startswith' member (no-member)

I tested this with multiple pylint versions, and the first version that has this behavior is pylint 3.3.0.

Command used

pylint test_pylint.py

Pylint output

************* Module test_pylint
test_pylint.py:16:7: E1101: Instance of 'Cls' has no 'startswith' member (no-member)

Expected behavior

Pylint should not report this as an error, because an f-string is a string and has the startswith() method.

Pylint version

pylint    3.3.0
astroid   3.3.3
Python 3.12.4 (main, Jun  6 2024, 18:26:44) [Clang 15.0.0 (clang-1500.3.9.4)]

OS / Environment

macOS Sonoma 14.6.1

@andy-maier andy-maier added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 22, 2024
@andy-maier andy-maier changed the title Pylint does not recognize f-string as string and reports no-member for startswith() Pylint 3.3.0 does not recognize f-string as string and reports no-member for startswith() Sep 22, 2024
@Pierre-Sassoulas Pierre-Sassoulas added Regression False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 22, 2024
@Pierre-Sassoulas Pierre-Sassoulas added this to the 3.3.1 milestone Sep 22, 2024
@jacobtylerwalls
Copy link
Member

Thanks for the report, regression in pylint-dev/astroid@3dbf139

@jacobtylerwalls
Copy link
Member

cc/ @ericvergnaud, would you by chance be able to have a look? 🙏

@jacobtylerwalls jacobtylerwalls added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Sep 22, 2024
@ericvergnaud
Copy link

cc/ @ericvergnaud, would you by chance be able to have a look? 🙏

Will do tomorrow

@oprypin
Copy link

oprypin commented Sep 23, 2024

I think I encountered a regression with the same root cause:

Regressed with astroid>=3.3:

"""Hi."""

class Foo:
    """Hi."""

    def hi(self):
        """Hi."""

    def __repr__(self):  # E0306: __repr__ does not return str (invalid-repr-returned)
        return f'{5}'

@ericvergnaud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs astroid update Needs an astroid update (probably a release too) before being mergable Regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants