-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
False positive unsubscriptable-object #9549
Comments
Hi, without the relevant import statements we won't be able to diagnose the issue. Please make sure to include all relevant code and dependencies :) |
@DarthLegiON thank you for the report, I’ve seen similar problems in my own project. Unfortunately, we didn’t investigate more but in our case deleting the virtual env and rebuilding it worked. Not a fix, I know, but it may unblock you? @DanielNoord the code shown above is a SQLAlchemy v2 declarative table mapping (docs). |
We have faced a similar problem too. @jenstroeger deleting the virtual env and rebuilding it doesn't fix our issue. We call This is the error we get: src/macaron/slsa_analyzer/checks/infer_artifact_pipeline_check.py:36:8: E1136: Value 'Mapped' is unsubscriptable (unsubscriptable-object)
src/macaron/slsa_analyzer/checks/infer_artifact_pipeline_check.py:39:16: E1136: Value 'Mapped' is unsubscriptable (unsubscriptable-object)
src/macaron/slsa_analyzer/checks/infer_artifact_pipeline_check.py:42:17: E1136: Value 'Mapped' is unsubscriptable (unsubscriptable-object)
src/macaron/slsa_analyzer/checks/infer_artifact_pipeline_check.py:45:13: E1136: Value 'Mapped' is unsubscriptable (unsubscriptable-object) You can find the code here: https://github.com/oracle/macaron/blob/f9be5387ae5ed4e04ceabb9b86579929d2ddcb8f/src/macaron/slsa_analyzer/checks/infer_artifact_pipeline_check.py#L36-L45 |
Could you provide the output of |
pylint 3.1.0
astroid 3.1.0
Python 3.11.3 (main, Apr 4 2023, 22:36:41) [GCC 11.3.0] sqlalchemy version: |
|
Sorry for the delay and thanks for your response! Base definition: Base = declarative_base() Rolegroup definition: class RoleGroup(Base):
__tablename__ = 'user_roles_groups'
id: Mapped[int] = mapped_column(Integer, primary_key=True)
give_role_channel_id: Mapped[int] = mapped_column(BigInteger)
give_role_message_id: Mapped[int] = mapped_column(BigInteger) @jenstroeger about deleting a virtual env. Maybe it will surprise you but I don't use one even in development mode. I run the project in Docker. And it fails both in local environment and in CI pipeline, but docker and pip was rebuilt every time. Problem disappears only when I delete the last line with |
I have the same error for class NetworkAwareModel(ApostroBaseModel):
__abstract__ = True
network_id: Mapped[int] = mapped_column(ForeignKey("network.id"))
@declared_attr
def network(self) -> Mapped[Network]:
"""Ensures that a new instance is created for each subclass"""
return relationship("Network")
|
If you're still intersted, here is my requirements.txt:
|
I had the same issue, by looking at the source code from the You can change the hinted types to match the return type of sqlalchemy functions ( from sqlalchemy import ForeignKey
from sqlalchemy.orm import MappedColumn, Relationship, mapped_column, relationship
from sqlalchemy.sql.sqltypes import String, Integer
class RoleReaction(Base):
__tablename__ = 'user_roles_reactions'
id: MappedColumn[int] = mapped_column(Integer, primary_key=True)
role_name: MappedColumn[str] = mapped_column(String)
reaction_name: MappedColumn[str] = mapped_column(String)
group_id: MappedColumn[int] = mapped_column(ForeignKey('user_roles_groups.id'))
group: Relationship[RoleGroup] = relationship(RoleGroup) It made my pylint error messages disappear. |
Bug description
Hi! I have weird behavior in my code.
Here is a code example:
It causes several
unsubscriptable-object
errors in pylint (look into the output section).But when I remove the last line (
group
definition), all of them disappear. When I move it upper, they don't. There is only one file in the whole project that causes such problem.Configuration
Command used
Pylint output
Expected behavior
No errors, 10/10
Pylint version
OS / Environment
Linux, docker
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: