-
- Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Closed
Copy link
Labels
AstroidRelated to astroidRelated to astroidC: unsubscriptable-objectIssues related to 'unsubscriptable-object' checkIssues related to 'unsubscriptable-object' checkFalse Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementation
Description
Bug description
# Optional method arguments or local scope variables are not properly inferred to be list[str] when in the if body. # example.py from typing import Optional from pydantic import BaseModel class Parents(BaseModel): name: str age: int children_name: Optional[list[str]] = None def get_first_children_name(self) -> Optional[str]: if self.children_name: return self.children_name[0] return NoneConfiguration
[FORMAT] # Maximum number of characters on a single line. max-line-length = 120 [MESSAGE CONTROL] disable = missing-module-docstring, missing-function-docstring, missing-class-docstring, fixme, unused-argument, broad-exception-caught, too-few-public-methods, import-error, no-name-in-module [BASIC] good-names= i, e, logger [MASTER] # disable false positives for Pydantic, which uses C extensions # see https://github.com/pydantic/pydantic/issues/1961#issuecomment-759522422 extension-pkg-whitelist = pydanticCommand used
pylint --reports=n example.pyPylint output
E1136: Value 'self.children_name' is unsubscriptable (unsubscriptable-object)Expected behavior
No error at all
Pylint version
pylint 2.17.5 astroid 2.15.6 Python 3.11.6 (main, Nov 6 2023, 08:36:52) [GCC 9.4.0]OS / Environment
No response
Additional dependencies
pydantic-core 2.6.3 typing-extensions 4.7.1gmetzker, CareF and valentjn
Metadata
Metadata
Assignees
Labels
AstroidRelated to astroidRelated to astroidC: unsubscriptable-objectIssues related to 'unsubscriptable-object' checkIssues related to 'unsubscriptable-object' checkFalse Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementation