Python dictionary for cspell that provides comprehensive spell checking support for Python source code files.
npx @tessl/cli install tessl/npm-cspell--dict-python@3.0.0CSpell Python Dictionary is a pre-built dictionary extension for cspell (Code Spell Checker) that provides comprehensive spell checking support for Python source code files. It contains specialized Python language dictionaries with keywords, built-in functions, and common Python programming terms, along with sophisticated pattern matching for Python-specific syntax.
npm install -g @cspell/dict-pythonThe package exports a cspell extension configuration that can be imported directly:
// Import as default in cspell.json
{
"import": ["@cspell/dict-python"]
}// Import via specific paths in cspell.json
{
"import": ["@cspell/dict-python/cspell"]
}// Import via explicit file path in cspell.json
{
"import": ["@cspell/dict-python/cspell-ext.json"]
}# Install globally
npm install -g @cspell/dict-python
# Register with cspell
cspell link add @cspell/dict-pythonAdd to your project's cspell.json configuration:
{
"import": ["@cspell/dict-python/cspell-ext.json"],
"files": ["src/**/*.py"]
}# Remove from cspell
cspell link remove @cspell/dict-pythonThe package provides a comprehensive Python dictionary system through several key components:
python.txt.gz, python-common.txt.gz) containing Python keywords and common termscspell-ext.json) with language-specific settingssrc/python/ and src/common/ directories used to build dictionariesThe main configuration that defines how cspell should handle Python files.
{
"id": "python",
"version": "0.2",
"readonly": true,
"name": "Python Dictionary",
"description": "Python Keyword Dictionary",
"dictionaryDefinitions": [
{
"name": "python",
"path": "./python.txt.gz",
"description": "Python Dictionary"
},
{
"name": "python-common",
"path": "./python-common.txt.gz",
"description": "Python Common Terms Dictionary"
}
],
"dictionaries": [],
"languageSettings": [
{
"languageId": "python",
"dictionaries": ["python", "python-common"],
"ignoreRegExpList": ["ignore_string_literal_prefix"],
"patterns": [...]
}
]
}The configuration defines two main dictionaries with their file paths and descriptions.
"dictionaryDefinitions": [
{
"name": "python",
"path": "./python.txt.gz",
"description": "Python Dictionary"
},
{
"name": "python-common",
"path": "./python-common.txt.gz",
"description": "Python Common Terms Dictionary"
}
]Available Dictionaries:
__init__, __call__, isinstance, enumerate)pythonic, django, numpy, matplotlib)Language-specific configuration that applies dictionaries and patterns to Python files.
"languageSettings": [
{
"languageId": "python",
"dictionaries": ["python", "python-common"],
"ignoreRegExpList": ["ignore_string_literal_prefix"],
"patterns": [...] // See Pattern Recognition section
}
]Advanced regex patterns for handling Python-specific syntax elements.
"patterns": [
{
"name": "ignore_string_literal_prefix",
"pattern": "/\\b(?:rf|fr|f|r|u|ur|b|br)'/gi"
},
{
"name": "string_binary",
"pattern": "/\\bbr?(['\"]).*?\\1/gi"
},
{
"name": "string_raw",
"pattern": "/\\bu?r(['\"]).*?\\1/gi"
},
{
"name": "string-multi-line",
"pattern": "/(\"\"\"|''')[^\\1]*?\\1/g"
},
{
"name": "string-single-line",
"pattern": "/((?<!\\\\)(?:'|\"))(?!\\1).*?(?<!\\1)(?<!\\\\)\\1(?!\\1)/g"
},
{
"name": "comment-single-line",
"pattern": "/#.*/g"
},
{
"name": "comment-multi-line",
"pattern": "/(\"\"\"|''')[^\\1]*?\\1/g"
},
{
"name": "strings",
"description": "Matches all strings in a Python File.",
"pattern": [
"/((?<!\\\\)(?:'|\"))(?!\\1).*?(?<!\\1)(?<!\\\\)\\1(?!\\1)/g",
"/(\"\"\"|''')[^\\1]*?\\1/g"
]
},
{
"name": "comments",
"description": "Matches all comments in a Python File.",
"pattern": [
"/#.*/g",
"/(\"\"\"|''')[^\\1]*?\\1/g"
]
}
]npm scripts for compiling dictionary files from source text files.
"scripts": {
"build": "yarn run build-python && yarn run build-common",
"build-python": "cspell-tools-cli compile \"src/python/*.txt\" \"src/additional_words.txt\" --split --keep-raw-case --merge python -o .",
"build-common": "cspell-tools-cli compile \"src/common/*.txt\" --keep-raw-case --merge python-common -o .",
"prepare": "yarn run build"
}Build Process:
python.txt.gz from source files in src/python/ plus src/additional_words.txtpython-common.txt.gz from source files in src/common/npm scripts for validating dictionary effectiveness against sample files.
"scripts": {
"test": "yarn run test-dictionary && yarn run test-samples",
"test-dictionary": "cspell -v -c ./cspell-ext.json --local=en --languageId=python \"src/python/py*.txt\"",
"test-samples": "cspell -v -c ./cspell-ext.json \"samples/**/*.py\""
}Test Process:
samples/ directoryAdditional scripts for maintaining the dictionary content:
"scripts": {
"update-python-lib": "./scripts/fetch-python.sh",
"prepublishOnly": "echo pre-publish"
}Maintenance Process:
The package provides multiple export paths for flexible integration:
"exports": {
".": "./cspell-ext.json",
"./cspell": "./cspell-ext.json",
"./cspell-ext.json": "./cspell-ext.json"
}All exports point to the same configuration file (cspell-ext.json) which contains the complete dictionary setup.
The published package includes only the essential files for distribution:
"files": [
"python.txt.gz",
"python-common.txt.gz",
"cspell-ext.json"
]These compressed dictionary files and configuration are all that's needed for cspell integration.
Contains essential Python language elements:
__init__, __call__, __str__, __repr__, __len__, etc.len, str, int, float, list, dict, tuple, set, etc.def, class, import, from, if, else, elif, for, while, etc.Exception, ValueError, TypeError, KeyError, etc.Contains frequently used Python programming vocabulary:
The dictionary is built from text source files organized in a specific directory structure:
"src/": {
"python/": {
"python.txt": "Core Python keywords and built-ins",
"python-lib.txt": "Python standard library terms"
},
"common/": {
"extra.txt": "Additional common programming terms"
},
"additional_words.txt": "Supplementary words for the Python dictionary"
}Source Files:
The package handles common integration issues:
Common error patterns and solutions:
# If dictionaries are not found
npm run build
# If global registration fails
cspell link remove @cspell/dict-python
cspell link add @cspell/dict-python
# If local import fails, check cspell.json syntax
{
"import": ["@cspell/dict-python/cspell-ext.json"]
}