Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
01eaa6f
Fixed bug that results in a false positive error when a class-scoped …
erictraut Mar 20, 2024
52a4701
Tweaked bidirectional type inference behaviors for lists to improve c…
erictraut Mar 20, 2024
7f468b8
Update Unicode range tables to match Unicode 15.1 (#7539)
debonte Mar 21, 2024
a6e787f
Use hex char codes and show code points for surrogate pairs (#7541)
debonte Mar 21, 2024
3da27fd
Fixed bug that resulted in a false positive error if a PEP-695 `type`…
erictraut Mar 21, 2024
bb95091
Fixed bug that results in incorrect type narrowing in the negative (f…
erictraut Mar 24, 2024
69a9151
Added check for the use of a non-runtime-checkable protocol class in …
erictraut Mar 24, 2024
fe41569
Fixed a bug that results in a false positive when a class-scoped Type…
erictraut Mar 24, 2024
7cf91f7
Changed the logic for metaclass instance variable lookups to ignore t…
erictraut Mar 25, 2024
1110ff9
push pylance to pyright (#7558)
heejaechang Mar 25, 2024
6ef2ca1
Updated typeshed stubs to the latest version.
erictraut Mar 25, 2024
1001904
Fixed a bug that results in a false positive `reportImplicitOverride`…
erictraut Mar 26, 2024
1f16813
Use a list for the configuration options (#7565)
CaselIT Mar 26, 2024
e9d923b
Fixed bad link in documentation.
erictraut Mar 26, 2024
9f02004
Published 1.1.356
erictraut Mar 27, 2024
6652c4a
pull-pylance-with-pyright-1.1.356-8444976018 (#7566)
PylanceBot Mar 27, 2024
b3723da
Fixed bug that results in a false positive error when explicitly call…
erictraut Mar 27, 2024
436c72c
Added support for negative (fall-through) type narrowing for subject …
erictraut Mar 27, 2024
a33feda
Fixed bug that results in false negative when a `__new__` or `__init_…
erictraut Mar 27, 2024
fc41d35
Fixed a bug that results in incorrect type narrowing of enums that de…
erictraut Mar 28, 2024
8312bbe
Fixed a type hole when a dictionary expression includes a dictionary …
erictraut Mar 28, 2024
c29473a
Enhanced dictionary type evaluation to support dictionary items that …
erictraut Mar 28, 2024
0668724
Refactored createFunctionFromConstructor for readability and maintain…
erictraut Mar 28, 2024
e4f3d61
Fixed bug that results in a type not being narrowed when using the `K…
erictraut Mar 30, 2024
bf4ddb3
Updated documentation for #7590.
erictraut Mar 30, 2024
7997351
Enhanced discriminated class support to include not only literal fiel…
erictraut Mar 30, 2024
b085a26
Changed the handling of `Final` variables (that are not explicitly ma…
erictraut Mar 31, 2024
efb4912
Fixed inconsistent handling of literal values in a list comprehension…
erictraut Mar 31, 2024
7bc313e
Fixed a bug that results in a false positive error when an unpacked T…
erictraut Apr 1, 2024
2b29345
Improved comment in completion provider. No functional change.
erictraut Apr 1, 2024
dab9c8f
Improved diagnostic message for access to unknown member in the case …
erictraut Apr 1, 2024
0b30e87
Improved return result for synthesized `get` method for closed `Typed…
erictraut Apr 2, 2024
5fd8830
Refactored tokenizer and parser output to help reduce the amount of m…
erictraut Apr 2, 2024
4106a09
Share heap usage numbers to support cache cleanup in VS code (#7605)
rchiodo Apr 2, 2024
b6c8b7f
Fixed a bug that results in incorrect inferred parameter types for an…
erictraut Apr 3, 2024
8752be7
Published 1.1.357
erictraut Apr 3, 2024
ed1dbe2
Fix crash when imports are not resolved (#7608)
rchiodo Apr 3, 2024
1eb0c99
Eliminated the need to retain a reference to the file contents in the…
erictraut Apr 3, 2024
727bce6
Pull Pylance with Pyright 1.1.357 (#7610)
debonte Apr 4, 2024
26db037
Fixed non-compliance issue with `TypeIs`, which is documented to have…
erictraut Apr 4, 2024
476447c
Fixed a bug that results in incorrect type evaluation when a sequence…
erictraut Apr 4, 2024
aff916f
Added optimization for TypedDict type assignments. Under certain circ…
erictraut Apr 4, 2024
627d3de
Modified the handling of enum class attributes so those with private …
erictraut Apr 4, 2024
6d1a5fd
Added support for narrowing of subject subexpression within a match s…
erictraut Apr 5, 2024
39dfca8
Added accessor method for class symbol table. This is in preparation …
erictraut Apr 6, 2024
4149eb3
Fixed bug that results in an intermittent false positive "circular de…
erictraut Apr 6, 2024
628e246
Fixed a bug that results in a false positive error under certain circ…
erictraut Apr 6, 2024
cfefcf4
Updated typeshed stubs to the latest version.
erictraut Apr 7, 2024
3b70417
Fixed bug that results in incorrect type evaluation in cases where a …
erictraut Apr 7, 2024
e65ac38
Fixed a bug that results in a false negative when a generic function …
erictraut Apr 7, 2024
d16990a
Fixed bug that results in inconsistent type narrowing on assignment b…
erictraut Apr 8, 2024
e9d19b5
Improved error handling for quoted annotations. Bytes, raw strings, a…
erictraut Apr 8, 2024
ed92822
Simplify editable install docs (#7643)
debonte Apr 9, 2024
bd08098
Skip unnecessary py.typed file exist checks. (#7652)
heejaechang Apr 9, 2024
ad1c378
Added an error message for a `Literal` type annotation that includes …
erictraut Apr 10, 2024
989ee29
Published 1.1.358
erictraut Apr 10, 2024
98d1523
Expanded support for `len(x) == L` type guard pattern (where x is a t…
erictraut Apr 10, 2024
d45ea4c
Push pylance changes to pyright (#7663)
debonte Apr 10, 2024
27e6b0e
Improved some diagnostic messages, moving away from the term "member"…
erictraut Apr 11, 2024
c212c23
More diagnostic message improvements: switched from "cannot assign to…
erictraut Apr 12, 2024
8c7e67d
Fixed a bug that leads to inconsistent behaviors when an assignment l…
erictraut Apr 12, 2024
dd09712
Extended type narrowing logic for `in` and `not in` operators that ta…
erictraut Apr 12, 2024
f2e277a
Fixed recent regression that results in a false positive error when a…
erictraut Apr 12, 2024
92f2284
Changed behavior when evaluating the upper bound expression, value co…
erictraut Apr 12, 2024
dfe4281
Fixed bug that results in a spurious `reportAbstractUsage` error when…
erictraut Apr 13, 2024
d7dce3b
Modified handling of annotated `self` parameter in `__init__` method …
erictraut Apr 13, 2024
567d025
Added missing check for the errant use of class-scoped type variables…
erictraut Apr 13, 2024
975c846
Fixed bug that results in incorrect type evaluation when solving a Pa…
erictraut Apr 14, 2024
1918364
Fixed a bug in bindFunctionToClassOrObject function that resulted in …
erictraut Apr 14, 2024
5c48084
Refactored the logic related to conversion of a class constructor to …
erictraut Apr 14, 2024
00d8f81
Fixed a bug that results in incorrect type evaluation when assigning …
erictraut Apr 14, 2024
2e537e9
Updated logic for converting a class constructor to a callable to con…
erictraut Apr 14, 2024
7f46092
Fixed a bug that leads to a false negative when an unparenthesized as…
erictraut Apr 14, 2024
9d87fe1
Changed the behavior when invoking constructor for `type[T]` where `T…
erictraut Apr 14, 2024
653e160
Modified behavior in constructor call code that previously applied so…
erictraut Apr 14, 2024
74880b8
Fixed broken build. I forgot to check in a test change.
erictraut Apr 14, 2024
43fe9a7
Changed behavior of conversion from class constructor to callable to …
erictraut Apr 14, 2024
71a3b60
Changed behavior of conversion from class constructor to callable to …
erictraut Apr 14, 2024
b1c4368
Changed behavior of conversion from class constructor to callable to …
erictraut Apr 14, 2024
8a7aed5
Added a check for the case where a frozen dataclass overrides a field…
erictraut Apr 14, 2024
8912c88
Fixed bug that results in false positive error under certain circumst…
erictraut Apr 16, 2024
cc3467f
Published 1.1.359
erictraut Apr 17, 2024
fc1b547
Push pylance changes to pyright (#7719)
debonte Apr 17, 2024
69ded75
Loc update from Pylance (#7720)
debonte Apr 17, 2024
a8399d3
Don't use Uri.Empty for default workspace. (#7654)
heejaechang Apr 17, 2024
0127fd6
log type evals perf when option is on (#7729)
heejaechang Apr 20, 2024
c7168d7
Added support for @deprecation messages for decorators that wrap a fu…
erictraut Apr 22, 2024
687fade
Fix a few typos in `docs/configuration.md` (#7739)
InSyncWithFoo Apr 22, 2024
f22576f
Moved check for invalid use of class-scoped TypeVar within a `self` a…
erictraut Apr 22, 2024
591b0d0
Update typing docs with Pycharm usage (#7744)
max-muoto Apr 22, 2024
9ca7cbd
Updated documentation to show that PEP 742 is no longer in draft form.
erictraut Apr 23, 2024
419a8f4
Fixed recent regression that affected unannotated `__call__` methods …
erictraut Apr 23, 2024
73d894c
Fixed recent regression that incorrectly narrowed the type of `kwargs…
erictraut Apr 23, 2024
d1461ce
Changed behavior to no longer exempt unguarded access to not-required…
erictraut Apr 23, 2024
cd483dc
Fixed bug in protocol matching that results in a false positive when …
erictraut Apr 23, 2024
3875288
Fixed a bug that results in a false positive error when bidirectional…
erictraut Apr 23, 2024
400bb92
Redesigned the handling of PEP 695-style type parameter scoping to be…
erictraut Apr 24, 2024
7c8e8ba
Updated typeshed stubs to the latest version.
erictraut Apr 24, 2024
d33a105
Fixed bug that leads to false negative when binding an object to an o…
erictraut Apr 24, 2024
e5c0b59
Fixed bug that leads to incorrect metatype for a class object that is…
erictraut Apr 24, 2024
f4afe40
Published 1.1.360
erictraut Apr 24, 2024
ffcd90b
Pull Pylance with Pyright 1.1.360 (#7761)
PylanceBot Apr 25, 2024
4bc8428
Follow-up pull from Pylance (#7766)
debonte Apr 25, 2024
547a150
Fixed a bug that results in a false negative when using bidirectional…
erictraut Apr 26, 2024
7194375
Fixed bug caused by incorrect synthesis of `item` and `keys` attribut…
erictraut Apr 26, 2024
c640765
Changed logic that synthesizes the constructor methods for a NamedTup…
erictraut Apr 26, 2024
c2203b9
Fixed bug that resulted in incorrect bidirectional type inference whe…
erictraut Apr 26, 2024
96d0145
Changed `TypeIs` to use the same logic as `isinstance` type narrowing…
erictraut Apr 26, 2024
6950622
Issue7779 (#7781)
erictraut Apr 26, 2024
0a8e1b7
Fixed documentation and json schema for `reportMissingTypeStubs` defa…
erictraut Apr 27, 2024
2743ba5
Fixed a bug that led to poor performance (effectively a hang) if an u…
erictraut Apr 27, 2024
47c53f9
Fixed a bug that results in a false positive error when using `__extr…
erictraut Apr 27, 2024
556608d
Fixed a bug that leads to an infinite loop when performing protocol m…
erictraut Apr 28, 2024
4c1eb61
Fixed a bug that results in a false positive error when `Callable()` …
erictraut Apr 29, 2024
1aed0e3
Fixed a false negative that occurs when reassigning a `Final` variabl…
erictraut Apr 29, 2024
fcf5b37
Changed the tokenizer so it is bug-for-bug compatible with the CPytho…
erictraut Apr 29, 2024
0af66f4
Fixed a bug that results in incorrect type evaluation when a global (…
erictraut Apr 29, 2024
01c512e
Fixed bug that resulted in incorrect evaluation of an identifier used…
erictraut Apr 30, 2024
42962e7
Split out type evaluator tests into more files and rebalanced them to…
erictraut Apr 30, 2024
582a93e
Fixed a bug that results in a false negative when an Unpack is used i…
erictraut Apr 30, 2024
de5a4f8
Fixed bug that produces incorrect output when converting to a textual…
erictraut Apr 30, 2024
ab84d41
Published 1.1.361
erictraut May 1, 2024
65ef82e
Merge tag '1.1.356' into merge-upstream
daweifeng-replit Apr 25, 2025
b219cae
Merge tag '1.1.357' into merge-upstream
daweifeng-replit Apr 25, 2025
07434ed
Merge tag '1.1.358' into merge-upstream
daweifeng-replit Apr 25, 2025
e1e6d67
Merge tag '1.1.359' into merge-upstream
daweifeng-replit Apr 25, 2025
8a22072
Merge tag '1.1.360' into merge-upstream
daweifeng-replit Apr 25, 2025
1a06062
Merge tag '1.1.361' into merge-upstream
daweifeng-replit Apr 25, 2025
95b78d0
Merge branch 'main' into merge-upstream
daweifeng-replit Apr 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
205 changes: 205 additions & 0 deletions build/generateUnicodeTables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# generateUnicodeTables.py
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
#
# Generates the content of unicode.ts based on the official Unicode
# character database.

import sys
import urllib.request
from io import TextIOWrapper


class Character:
def __init__(self, code: int, category: str, *, end: int | None = None):
self.code = code
self.category = category

self.hasSurrogate = code > 0xFFFF
if self.hasSurrogate:
unicodeChar = chr(code)
utf16 = unicodeChar.encode("utf-16")
rawHex = utf16.hex()
hex = rawHex[4:]

self.highSurrogate = int(hex[2:4] + hex[0:2], base=16)
self.lowSurrogate = int(hex[6:8] + hex[4:6], base=16)


class CharacterRange:
def __init__(self, start: Character, end: Character):
self.start = start
self.end = end


def downloadUnicodeData(unicodeVersion: str) -> str:
url = f"https://www.unicode.org/Public/{unicodeVersion}.0/ucd/UnicodeData.txt"
(path, _) = urllib.request.urlretrieve(url)
return path


def parseFile(filePath: str) -> list[Character]:
with open(filePath, "r") as reader:
lines = reader.readlines()
chars: list[Character] = []
for i in range(len(lines)):
line = lines[i]
splitOnSemicolon = line.split(";")
charCode = int(splitOnSemicolon[0], base=16)
category = splitOnSemicolon[2]

if splitOnSemicolon[1].endswith(", First>"):
# Legacy range syntax
# D800;<Non Private Use High Surrogate, First>;Cs;0;L;;;;;N;;;;;
# DB7F;<Non Private Use High Surrogate, Last>;Cs;0;L;;;;;N;;;;;
nextLine = lines[i + 1]
nextSplitOnSemicolon = nextLine.split(";")
nextCharCode = int(nextSplitOnSemicolon[0], base=16)
for ord in range(charCode, nextCharCode + 1):
chars.append(Character(ord, category))
elif splitOnSemicolon[1].endswith(", Last>"):
continue
else:
chars.append(Character(charCode, category))

return chars


# Given a collection of characters, returns a list of ranges of contiguous
# characters. Contiguous means that the character codes are sequential with
# no gaps and the characters all have the same category. For character codes
# greater than 0xFFFF, contiguous means that the high surrogate is the same
# and the low surrogate values are sequential with no gaps. So, two charcter
# codes might be sequential numerically but have different high surrogates,
# and therefore would not be members of the same range.
def getSurrogateRanges(chars: list[Character]) -> list[CharacterRange]:
surrogateRanges: list[CharacterRange] = []

consecutiveRangeStartChar: Character | None = None
previousChar: Character | None = None
for char in chars:
if not consecutiveRangeStartChar:
consecutiveRangeStartChar = char

if previousChar:
if not previousChar.hasSurrogate and not char.hasSurrogate:
if (
char.code == previousChar.code + 1
and char.category == previousChar.category
):
pass
elif not previousChar.hasSurrogate and char.hasSurrogate:
consecutiveRangeStartChar = char
else:
if (
char.highSurrogate == previousChar.highSurrogate
and char.lowSurrogate == previousChar.lowSurrogate + 1
and char.category == previousChar.category
):
pass
else:
surrogateRanges.append(
CharacterRange(consecutiveRangeStartChar, previousChar)
)
consecutiveRangeStartChar = char

previousChar = char

return surrogateRanges


# Write out a table of all character codes within the specified category. These are
# the full hex character codes (Unicode code points) not surrogate values. Sequential
# ranges of character codes are written as arrays of two numbers (start and end) to
# save space.
def writeRangeTable(writer: TextIOWrapper, category: str, chars: list[Character]):
chars = [ch for ch in chars if ch.category == category]

writer.write(f"export const unicode{category}: UnicodeRangeTable = [\n")

consecutiveRangeStartChar: Character | None = None
for i in range(len(chars)):
char = chars[i]

if not consecutiveRangeStartChar:
consecutiveRangeStartChar = char

if i + 1 >= len(chars) or chars[i + 1].code != char.code + 1:
if consecutiveRangeStartChar.code == char.code:
writer.write(f" 0x{consecutiveRangeStartChar.code:04X},\n")
else:
writer.write(f" [0x{consecutiveRangeStartChar.code:04X}, 0x{char.code:04X}],\n")

consecutiveRangeStartChar = None

writer.write("];\n\n")


# Write out a table of all characters within the specified category using their UTF-16
# values. Characters are grouped by high surrogate value. Sequential ranges of low
# surrogate values are written as arrays of two numbers (start and end) to save space.
def writeSurrogateRangeTable(
writer: TextIOWrapper, category: str, surrogateRanges: list[CharacterRange]
):
surrogateRanges = [r for r in surrogateRanges if r.start.category == category]

if len(surrogateRanges) == 0:
return

writer.write(
f"export const unicode{category}Surrogate: UnicodeSurrogateRangeTable = {{\n"
)

previousCharRange: CharacterRange | None = None
for charRange in surrogateRanges:
if (
previousCharRange
and charRange.start.highSurrogate != previousCharRange.start.highSurrogate
):
writer.write(" ],\n")
previousCharRange = None

if not previousCharRange:
writer.write(f" 0x{charRange.start.highSurrogate:04X}: [\n")
previousCharRange = charRange

if charRange.start.lowSurrogate == charRange.end.lowSurrogate:
writer.write(f" 0x{charRange.start.lowSurrogate:04X}, // 0x{charRange.start.code:04X}\n")
else:
writer.write(
f" [0x{charRange.start.lowSurrogate:04X}, 0x{charRange.end.lowSurrogate:04X}], // 0x{charRange.start.code:04X}..0x{charRange.end.code:04X}\n"
)

writer.write(" ],\n")
writer.write("};\n\n")


unicodeVersion = "15.1" if len(sys.argv) <= 1 else sys.argv[1]
path = downloadUnicodeData(unicodeVersion)
chars = parseFile(path)
surrogateRanges = getSurrogateRanges(chars)

with open("packages/pyright-internal/src/parser/unicode.ts", "w") as writer:
writer.write(
f"""/*
* unicode.ts
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
*
* Tables that encode Unicode character codes for various Unicode-
* defined categories used in the Python spec.
*
* Generated by build/generateUnicodeTables.py from the UnicodeData.txt
* metadata file for Unicode {unicodeVersion}.
*/

export type UnicodeRange = [number, number] | number;
export type UnicodeRangeTable = UnicodeRange[];
export type UnicodeSurrogateRangeTable = {{ [surrogate: number]: UnicodeRange[] }};

"""
)

for category in ["Lu", "Ll", "Lt", "Lo", "Lm", "Nl", "Mn", "Mc", "Nd", "Pc"]:
writeRangeTable(writer, category, chars)
writeSurrogateRangeTable(writer, category, surrogateRanges)
2 changes: 1 addition & 1 deletion docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- [Execution Environments](configuration.md#execution-environment-options)
- [Sample pyrightconfig.json](configuration.md#sample-config-file)
- [Sample pyproject.toml](configuration.md#sample-pyprojecttoml-file)
- [Diagnostic Rule Defaults](configuration.md#diagnostic-rule-defaults)
- [Diagnostic Settings Defaults](configuration.md#diagnostic-settings-defaults)
- [Locale Configuration](configuration.md#locale-configuration)
- [Language Server Settings](settings.md)
- [Command Line Interface](command-line.md)
Expand Down
Loading
Loading