-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
AstroidRelated to astroidRelated to astroidControl flowRequires control flow understandingRequires control flow understandingFalse Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeNeeds astroid updateNeeds an astroid update (probably a release too) before being mergableNeeds an astroid update (probably a release too) before being mergable
Description
Bug description
Pylint incorrectly reports E1102: not-callable
when calling a property that returns a union type with None
, even after explicit None checking.
The issue occurs when:
- A property returns
CallableType | None
- Code explicitly checks
if self.property:
before calling - The callable type has a
__call__
method
Minimal reproduction:
from abc import ABC, abstractmethod
class CallableBase(ABC):
"""Simple callable abstract base class."""
@abstractmethod
def __call__(self, data: str) -> str:
pass
class ConcreteCallable(CallableBase):
"""Concrete implementation."""
def __call__(self, data: str) -> str:
return f"processed: {data}"
class Container:
"""Demonstrates the property inference issue."""
def __init__(self, processor: CallableBase | None = None):
self.__processor = processor
@property
def processor(self) -> CallableBase | None:
"""Property returning union type - causes pylint issue."""
return self.__processor
def process_with_property(self, data: str) -> str:
"""Uses property - pylint incorrectly flags as not-callable."""
if self.processor: # Clearly checks for None
return self.processor(data) # pylint: E1102 not-callable
return data
def process_with_attribute(self, data: str) -> str:
"""Uses direct attribute - pylint works fine."""
if self.__processor: # Same logic, different access
return self.__processor(data) # No pylint error
return data
Command used
pylint test.py
Pylint output
************* Module test
test.py:35:19: E1102: self.processor is not callable (not-callable)
------------------------------------------------------------------
Your code has been rated at 7.92/10 (previous run: 7.83/10, +0.09)
Expected behavior
Do not emit a message here
Pylint version
pylint --version
pylint 4.0.0-dev0
astroid 4.0.0b0
Python 3.13.5 (main, Jul 1 2025, 18:31:42) [MSC v.1944 64 bit (AMD64)]
OS / Environment
Windows 10
Metadata
Metadata
Assignees
Labels
AstroidRelated to astroidRelated to astroidControl flowRequires control flow understandingRequires control flow understandingFalse Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeNeeds astroid updateNeeds an astroid update (probably a release too) before being mergableNeeds an astroid update (probably a release too) before being mergable