Skip to content

Commit 8fbd00a

Browse files
committed
Test that illustrates sympy metaclass problem
1 parent 840a310 commit 8fbd00a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test-data/unit/check-classes.test

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6663,6 +6663,39 @@ class MyMetaClass(type):
66636663
class MyClass(metaclass=MyMetaClass):
66646664
pass
66656665

6666+
6667+
[case testMetaclassPlaceholderNode]
6668+
from sympy.assumptions import ManagedProperties
6669+
from sympy.ops import AssocOp
6670+
reveal_type(AssocOp.x) # N: Revealed type is "sympy.basic.Basic"
6671+
reveal_type(AssocOp.y) # N: Revealed type is "builtins.int"
6672+
6673+
[file sympy/__init__.py]
6674+
6675+
[file sympy/assumptions.py]
6676+
from .basic import Basic
6677+
class ManagedProperties(type):
6678+
x: Basic
6679+
y: int
6680+
# The problem is with the next line,
6681+
# it creates the following order (classname, metaclass):
6682+
# 1. Basic NameExpr(ManagedProperties)
6683+
# 2. AssocOp None
6684+
# 3. ManagedProperties None
6685+
# 4. Basic NameExpr(ManagedProperties [sympy.assumptions.ManagedProperties])
6686+
# So, `AssocOp` will still have `metaclass_type` as `None`
6687+
# and all its `mro` types will have `declared_metaclass` as `None`.
6688+
from sympy.ops import AssocOp
6689+
6690+
[file sympy/basic.py]
6691+
from .assumptions import ManagedProperties
6692+
class Basic(metaclass=ManagedProperties): ...
6693+
6694+
[file sympy/ops.py]
6695+
from sympy.basic import Basic
6696+
class AssocOp(Basic): ...
6697+
6698+
66666699
[case testGenericOverride]
66676700
from typing import Generic, TypeVar, Any
66686701

0 commit comments

Comments
 (0)