-
Notifications
You must be signed in to change notification settings - Fork 765
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
Pyspark: cannot access member "config" for type "classproperty" #4577
Comments
Without the stubs, pyspark has this for the 'builder' definition # TODO(SPARK-38912): Replace @classproperty with @classmethod + @property once support for
# Python 3.8 is dropped.
#
# In Python 3.9, the @property decorator has been made compatible with the
# @classmethod decorator (https://docs.python.org/3.9/library/functions.html#classmethod)
#
# @classmethod + @property is also affected by a bug in Python's docstring which was backported
# to Python 3.9.6 (https://github.com/python/cpython/pull/28838)
@classproperty
def builder(cls) -> Builder:
"""Creates a :class:`Builder` for constructing a :class:`SparkSession`."""
return cls.Builder() Whereas the stubs have this (and force pyspark to also move backwards to 3.0.1): builder: SparkSession.Builder The If you switch pyspark to add what they suggested in the comment, it starts working. For example this: if TYPE_CHECKING:
@classmethod
@property
def builder(cls) -> Builder:
"""Creates a :class:`Builder` for constructing a :class:`SparkSession`."""
return cls.Builder()
else:
@classproperty
def builder(cls) -> Builder:
"""Creates a :class:`Builder` for constructing a :class:`SparkSession`."""
return cls.Builder() I think this would be a bug for pyspark to fix. By either providing the appropriate decorators, or perhaps fixing their @erictraut do you have any thoughts? |
A simpler repro is this: class classproperty(property):
def __get__(self, instance: Any, owner: Any = None) -> "TestSession.Builder":
if self.fget:
return classmethod(self.fget).__get__(None, owner)()
raise Exception()
class TestSession:
class Builder:
x: int
def __init__(self):
x = 4
@classproperty
def builder(cls) -> Builder:
return TestSession.Builder()
b = TestSession.builder
reveal_type(b.x) # Error here. Type of b.x is unknown |
@rchiodo Thanks for the prompt response, and apologies for the lack of succinct reproducible example. This is a bit beyond my coding level. Should I just be adding that code to the |
@Daniel-Considine I don't think there's anything you can add to I think the change I suggested for pyspark would be the way to "fix" it. if TYPE_CHECKING:
@classmethod
@property
def builder(cls) -> Builder:
"""Creates a :class:`Builder` for constructing a :class:`SparkSession`."""
return cls.Builder()
else:
@classproperty
def builder(cls) -> Builder:
"""Creates a :class:`Builder` for constructing a :class:`SparkSession`."""
return cls.Builder() That change goes here: At least that would allow Pylance to understand that |
@rchiodo |
I still have this error, was it solved? I am using pyspark 3.5.0 |
I believe you'd have to ask Pyspark, It's a problem in their usage of The list of allowed/known decorators is specified here: That's the python typing spec. |
It looks like the Pyspark 4.0 preview release takes care of this issue. I guess that's a good sign. |
In version However, the problem persists in version |
Environment data
Code Snippet
Actual behavior
This code works fine when running scripts and Jupyter cells, but still the above message and failure to access functions etc.
I believe it's a stub issue, as pip install pyspark-stubs fixes the issue. However this library is meant to be integrated with the base pyspark distribution now, and is not compatible with more recent pyspark versions. I am unsure on whether the issue is with pylance accessing the stubs/typings that are now included in pyspark, or if the issue is on their end.
Logs
pylance.log
The text was updated successfully, but these errors were encountered: