snowflakedb / snowflakedb/snowpark-python
SNOW-1055426: Typing breaks on pyright due to improper alias definitions
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 341
- Forks
- 155
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 27
Description
Hey, I've looked into the type definitions and it looks like there's a bunch of decisions you made which make pyright (and therefore by extension VSCode Intellisense) not work for most of the cases.
Examples here:
ColumnOrName = Union["snowflake.snowpark.column.Column", str]
This doesn't work and the string evaluates to Unknown. Is there any reason to use it instead of a regular import?
PYTHON_TO_SNOW_TYPE_MAPPINGS = {
NoneType: NullType,
bool: BooleanType,
int: LongType,
float: FloatType,
str: StringType,
bytearray: BinaryType,
decimal.Decimal: DecimalType,
datetime.date: DateType,
datetime.datetime: TimestampType,
datetime.time: TimeType,
bytes: BinaryType,
}
VALID_PYTHON_TYPES_FOR_LITERAL_VALUE = (
*PYTHON_TO_SNOW_TYPE_MAPPINGS.keys(),
list,
tuple,
dict,
)
VALID_SNOWPARK_TYPES_FOR_LITERAL_VALUE = (
*PYTHON_TO_SNOW_TYPE_MAPPINGS.values(),
_NumericType,
ArrayType,
MapType,
VariantType,
)
LiteralType = Union[VALID_PYTHON_TYPES_FOR_LITERAL_VALUE]
The above also doesn't work due to requiring runtime evaluations for the types to work. It technically its allowed in python, but it obviously makes type-checkers work much harder. It should be instead replaced with regular type expressions like Unions etc.
Please answer these questions before submitting your issue. Thanks!
- What version of Python are you using?
Python 3.11.7
- What operating system and processor architecture are you using?
macOS-14.3-arm64-arm-64bit
- What are the component versions in the environment (
pip freeze)?
snowflake-snowpark-python==1.12.1
- What did you do?
Installed snowpark, tried to hover over types within vscode.
- What did you expect to see?
The type should be there, instead its unknown.
- Can you set logging to DEBUG and collect the logs?
Not relevant.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the type definitions containing ColumnOrName, PYTHON_TO_SNOW_TYPE_MAPPINGS, VALID_PYTHON_TYPES_FOR_LITERAL_VALUE, and LiteralType. Reproduce the hover behavior in VSCode with Python 3.11.7 and Snowpark 1.12.1, then verify that the affected aliases resolve to useful types without requiring runtime evaluation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, vscode
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100