Reverted the change for #5446 because it's causing false positive errors.

This commit is contained in:
Eric Traut 2023-07-15 09:23:42 -07:00
parent 132e7edeab
commit 2a096860c1
4 changed files with 0 additions and 95 deletions

View File

@ -15563,15 +15563,6 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
? new Map<string, Symbol>(innerScope.symbolTable)
: new Map<string, Symbol>();
// Determine whether the class should inherit __hash__. If a class defines
// __eq__ but doesn't define __hash__ then __hash__ is set to None.
if (classType.details.fields.has('__eq__') && !classType.details.fields.has('__hash__')) {
classType.details.fields.set(
'__hash__',
Symbol.createWithType(SymbolFlags.ClassMember | SymbolFlags.ClassVar, NoneType.createInstance())
);
}
// Determine whether the class's instance variables are constrained
// to those defined by __slots__. We need to do this prior to dataclass
// processing because dataclasses can implicitly add to the slots

View File

@ -1,55 +0,0 @@
# This sample tests that unhashable user classes are detected as unhashable.
class A:
...
s1 = {A()}
d1 = {A(): 100}
class B:
def __eq__(self, other):
...
# Both of these should generate an error because a class that
# defines __eq__ but not __hash__ is not hashable.
s2 = {B()}
d2 = {B(): 100}
class C:
__hash__: None = None
class D(B, C):
...
# Both of these should generate an error because B is unhashable.
s3 = {UnhashableSub()}
d3 = {UnhashableSub(): 100}
class E:
def __hash__(self):
...
class F(D, E):
...
# Both of these should generate an error because D is unhashable.
s4 = {F()}
d4 = {F(): 100}
class G(E, D):
...
s5 = {G()}
d5 = {G(): 100}

View File

@ -1,21 +0,0 @@
# This sample tests that __hash__ is set to None if
# __hash__ isn't set but __eq__ is.
class A:
...
A().__hash__()
class B:
def __eq__(self, value: object) -> bool:
...
...
# This should generate an error because __hash__ is implicitly set to None
# for a class that defines __eq__ but not __hash__.
B().__hash__()

View File

@ -145,16 +145,6 @@ test('Hashability1', () => {
TestUtils.validateResults(analysisResults, 10);
});
test('Hashability2', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['hashability2.py']);
TestUtils.validateResults(analysisResults, 6);
});
test('Hashability3', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['hashability3.py']);
TestUtils.validateResults(analysisResults, 1);
});
test('Override1', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['override1.py']);
TestUtils.validateResults(analysisResults, 3);