assumptions.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. """
  2. This module contains the machinery handling assumptions.
  3. Do also consider the guide :ref:`assumptions-guide`.
  4. All symbolic objects have assumption attributes that can be accessed via
  5. ``.is_<assumption name>`` attribute.
  6. Assumptions determine certain properties of symbolic objects and can
  7. have 3 possible values: ``True``, ``False``, ``None``. ``True`` is returned if the
  8. object has the property and ``False`` is returned if it does not or cannot
  9. (i.e. does not make sense):
  10. >>> from sympy import I
  11. >>> I.is_algebraic
  12. True
  13. >>> I.is_real
  14. False
  15. >>> I.is_prime
  16. False
  17. When the property cannot be determined (or when a method is not
  18. implemented) ``None`` will be returned. For example, a generic symbol, ``x``,
  19. may or may not be positive so a value of ``None`` is returned for ``x.is_positive``.
  20. By default, all symbolic values are in the largest set in the given context
  21. without specifying the property. For example, a symbol that has a property
  22. being integer, is also real, complex, etc.
  23. Here follows a list of possible assumption names:
  24. .. glossary::
  25. commutative
  26. object commutes with any other object with
  27. respect to multiplication operation. See [12]_.
  28. complex
  29. object can have only values from the set
  30. of complex numbers. See [13]_.
  31. imaginary
  32. object value is a number that can be written as a real
  33. number multiplied by the imaginary unit ``I``. See
  34. [3]_. Please note that ``0`` is not considered to be an
  35. imaginary number, see
  36. `issue #7649 <https://github.com/sympy/sympy/issues/7649>`_.
  37. real
  38. object can have only values from the set
  39. of real numbers.
  40. extended_real
  41. object can have only values from the set
  42. of real numbers, ``oo`` and ``-oo``.
  43. integer
  44. object can have only values from the set
  45. of integers.
  46. odd
  47. even
  48. object can have only values from the set of
  49. odd (even) integers [2]_.
  50. prime
  51. object is a natural number greater than 1 that has
  52. no positive divisors other than 1 and itself. See [6]_.
  53. composite
  54. object is a positive integer that has at least one positive
  55. divisor other than 1 or the number itself. See [4]_.
  56. zero
  57. object has the value of 0.
  58. nonzero
  59. object is a real number that is not zero.
  60. rational
  61. object can have only values from the set
  62. of rationals.
  63. algebraic
  64. object can have only values from the set
  65. of algebraic numbers [11]_.
  66. transcendental
  67. object can have only values from the set
  68. of transcendental numbers [10]_.
  69. irrational
  70. object value cannot be represented exactly by :class:`~.Rational`, see [5]_.
  71. finite
  72. infinite
  73. object absolute value is bounded (arbitrarily large).
  74. See [7]_, [8]_, [9]_.
  75. negative
  76. nonnegative
  77. object can have only negative (nonnegative)
  78. values [1]_.
  79. positive
  80. nonpositive
  81. object can have only positive (nonpositive) values.
  82. extended_negative
  83. extended_nonnegative
  84. extended_positive
  85. extended_nonpositive
  86. extended_nonzero
  87. as without the extended part, but also including infinity with
  88. corresponding sign, e.g., extended_positive includes ``oo``
  89. hermitian
  90. antihermitian
  91. object belongs to the field of Hermitian
  92. (antihermitian) operators.
  93. Examples
  94. ========
  95. >>> from sympy import Symbol
  96. >>> x = Symbol('x', real=True); x
  97. x
  98. >>> x.is_real
  99. True
  100. >>> x.is_complex
  101. True
  102. See Also
  103. ========
  104. .. seealso::
  105. :py:class:`sympy.core.numbers.ImaginaryUnit`
  106. :py:class:`sympy.core.numbers.Zero`
  107. :py:class:`sympy.core.numbers.One`
  108. :py:class:`sympy.core.numbers.Infinity`
  109. :py:class:`sympy.core.numbers.NegativeInfinity`
  110. :py:class:`sympy.core.numbers.ComplexInfinity`
  111. Notes
  112. =====
  113. The fully-resolved assumptions for any SymPy expression
  114. can be obtained as follows:
  115. >>> from sympy.core.assumptions import assumptions
  116. >>> x = Symbol('x',positive=True)
  117. >>> assumptions(x + I)
  118. {'commutative': True, 'complex': True, 'composite': False, 'even':
  119. False, 'extended_negative': False, 'extended_nonnegative': False,
  120. 'extended_nonpositive': False, 'extended_nonzero': False,
  121. 'extended_positive': False, 'extended_real': False, 'finite': True,
  122. 'imaginary': False, 'infinite': False, 'integer': False, 'irrational':
  123. False, 'negative': False, 'noninteger': False, 'nonnegative': False,
  124. 'nonpositive': False, 'nonzero': False, 'odd': False, 'positive':
  125. False, 'prime': False, 'rational': False, 'real': False, 'zero':
  126. False}
  127. Developers Notes
  128. ================
  129. The current (and possibly incomplete) values are stored
  130. in the ``obj._assumptions dictionary``; queries to getter methods
  131. (with property decorators) or attributes of objects/classes
  132. will return values and update the dictionary.
  133. >>> eq = x**2 + I
  134. >>> eq._assumptions
  135. {}
  136. >>> eq.is_finite
  137. True
  138. >>> eq._assumptions
  139. {'finite': True, 'infinite': False}
  140. For a :class:`~.Symbol`, there are two locations for assumptions that may
  141. be of interest. The ``assumptions0`` attribute gives the full set of
  142. assumptions derived from a given set of initial assumptions. The
  143. latter assumptions are stored as ``Symbol._assumptions_orig``
  144. >>> Symbol('x', prime=True, even=True)._assumptions_orig
  145. {'even': True, 'prime': True}
  146. The ``_assumptions_orig`` are not necessarily canonical nor are they filtered
  147. in any way: they records the assumptions used to instantiate a Symbol and (for
  148. storage purposes) represent a more compact representation of the assumptions
  149. needed to recreate the full set in ``Symbol.assumptions0``.
  150. References
  151. ==========
  152. .. [1] https://en.wikipedia.org/wiki/Negative_number
  153. .. [2] https://en.wikipedia.org/wiki/Parity_%28mathematics%29
  154. .. [3] https://en.wikipedia.org/wiki/Imaginary_number
  155. .. [4] https://en.wikipedia.org/wiki/Composite_number
  156. .. [5] https://en.wikipedia.org/wiki/Irrational_number
  157. .. [6] https://en.wikipedia.org/wiki/Prime_number
  158. .. [7] https://en.wikipedia.org/wiki/Finite
  159. .. [8] https://docs.python.org/3/library/math.html#math.isfinite
  160. .. [9] https://numpy.org/doc/stable/reference/generated/numpy.isfinite.html
  161. .. [10] https://en.wikipedia.org/wiki/Transcendental_number
  162. .. [11] https://en.wikipedia.org/wiki/Algebraic_number
  163. .. [12] https://en.wikipedia.org/wiki/Commutative_property
  164. .. [13] https://en.wikipedia.org/wiki/Complex_number
  165. """
  166. from sympy.utilities.exceptions import sympy_deprecation_warning
  167. from .facts import FactRules, FactKB
  168. from .sympify import sympify
  169. from sympy.core.random import _assumptions_shuffle as shuffle
  170. from sympy.core.assumptions_generated import generated_assumptions as _assumptions
  171. def _load_pre_generated_assumption_rules():
  172. """ Load the assumption rules from pre-generated data
  173. To update the pre-generated data, see :method::`_generate_assumption_rules`
  174. """
  175. _assume_rules=FactRules._from_python(_assumptions)
  176. return _assume_rules
  177. def _generate_assumption_rules():
  178. """ Generate the default assumption rules
  179. This method should only be called to update the pre-generated
  180. assumption rules.
  181. To update the pre-generated assumptions run: bin/ask_update.py
  182. """
  183. _assume_rules = FactRules([
  184. 'integer -> rational',
  185. 'rational -> real',
  186. 'rational -> algebraic',
  187. 'algebraic -> complex',
  188. 'transcendental == complex & !algebraic',
  189. 'real -> hermitian',
  190. 'imaginary -> complex',
  191. 'imaginary -> antihermitian',
  192. 'extended_real -> commutative',
  193. 'complex -> commutative',
  194. 'complex -> finite',
  195. 'odd == integer & !even',
  196. 'even == integer & !odd',
  197. 'real -> complex',
  198. 'extended_real -> real | infinite',
  199. 'real == extended_real & finite',
  200. 'extended_real == extended_negative | zero | extended_positive',
  201. 'extended_negative == extended_nonpositive & extended_nonzero',
  202. 'extended_positive == extended_nonnegative & extended_nonzero',
  203. 'extended_nonpositive == extended_real & !extended_positive',
  204. 'extended_nonnegative == extended_real & !extended_negative',
  205. 'real == negative | zero | positive',
  206. 'negative == nonpositive & nonzero',
  207. 'positive == nonnegative & nonzero',
  208. 'nonpositive == real & !positive',
  209. 'nonnegative == real & !negative',
  210. 'positive == extended_positive & finite',
  211. 'negative == extended_negative & finite',
  212. 'nonpositive == extended_nonpositive & finite',
  213. 'nonnegative == extended_nonnegative & finite',
  214. 'nonzero == extended_nonzero & finite',
  215. 'zero -> even & finite',
  216. 'zero == extended_nonnegative & extended_nonpositive',
  217. 'zero == nonnegative & nonpositive',
  218. 'nonzero -> real',
  219. 'prime -> integer & positive',
  220. 'composite -> integer & positive & !prime',
  221. '!composite -> !positive | !even | prime',
  222. 'irrational == real & !rational',
  223. 'imaginary -> !extended_real',
  224. 'infinite == !finite',
  225. 'noninteger == extended_real & !integer',
  226. 'extended_nonzero == extended_real & !zero',
  227. ])
  228. return _assume_rules
  229. _assume_rules = _load_pre_generated_assumption_rules()
  230. _assume_defined = _assume_rules.defined_facts.copy()
  231. _assume_defined.add('polar')
  232. _assume_defined = frozenset(_assume_defined)
  233. def assumptions(expr, _check=None):
  234. """return the T/F assumptions of ``expr``"""
  235. n = sympify(expr)
  236. if n.is_Symbol:
  237. rv = n.assumptions0 # are any important ones missing?
  238. if _check is not None:
  239. rv = {k: rv[k] for k in set(rv) & set(_check)}
  240. return rv
  241. rv = {}
  242. for k in _assume_defined if _check is None else _check:
  243. v = getattr(n, 'is_{}'.format(k))
  244. if v is not None:
  245. rv[k] = v
  246. return rv
  247. def common_assumptions(exprs, check=None):
  248. """return those assumptions which have the same True or False
  249. value for all the given expressions.
  250. Examples
  251. ========
  252. >>> from sympy.core import common_assumptions
  253. >>> from sympy import oo, pi, sqrt
  254. >>> common_assumptions([-4, 0, sqrt(2), 2, pi, oo])
  255. {'commutative': True, 'composite': False,
  256. 'extended_real': True, 'imaginary': False, 'odd': False}
  257. By default, all assumptions are tested; pass an iterable of the
  258. assumptions to limit those that are reported:
  259. >>> common_assumptions([0, 1, 2], ['positive', 'integer'])
  260. {'integer': True}
  261. """
  262. check = _assume_defined if check is None else set(check)
  263. if not check or not exprs:
  264. return {}
  265. # get all assumptions for each
  266. assume = [assumptions(i, _check=check) for i in sympify(exprs)]
  267. # focus on those of interest that are True
  268. for i, e in enumerate(assume):
  269. assume[i] = {k: e[k] for k in set(e) & check}
  270. # what assumptions are in common?
  271. common = set.intersection(*[set(i) for i in assume])
  272. # which ones hold the same value
  273. a = assume[0]
  274. return {k: a[k] for k in common if all(a[k] == b[k]
  275. for b in assume)}
  276. def failing_assumptions(expr, **assumptions):
  277. """
  278. Return a dictionary containing assumptions with values not
  279. matching those of the passed assumptions.
  280. Examples
  281. ========
  282. >>> from sympy import failing_assumptions, Symbol
  283. >>> x = Symbol('x', positive=True)
  284. >>> y = Symbol('y')
  285. >>> failing_assumptions(6*x + y, positive=True)
  286. {'positive': None}
  287. >>> failing_assumptions(x**2 - 1, positive=True)
  288. {'positive': None}
  289. If *expr* satisfies all of the assumptions, an empty dictionary is returned.
  290. >>> failing_assumptions(x**2, positive=True)
  291. {}
  292. """
  293. expr = sympify(expr)
  294. failed = {}
  295. for k in assumptions:
  296. test = getattr(expr, 'is_%s' % k, None)
  297. if test is not assumptions[k]:
  298. failed[k] = test
  299. return failed # {} or {assumption: value != desired}
  300. def check_assumptions(expr, against=None, **assume):
  301. """
  302. Checks whether assumptions of ``expr`` match the T/F assumptions
  303. given (or possessed by ``against``). True is returned if all
  304. assumptions match; False is returned if there is a mismatch and
  305. the assumption in ``expr`` is not None; else None is returned.
  306. Explanation
  307. ===========
  308. *assume* is a dict of assumptions with True or False values
  309. Examples
  310. ========
  311. >>> from sympy import Symbol, pi, I, exp, check_assumptions
  312. >>> check_assumptions(-5, integer=True)
  313. True
  314. >>> check_assumptions(pi, real=True, integer=False)
  315. True
  316. >>> check_assumptions(pi, negative=True)
  317. False
  318. >>> check_assumptions(exp(I*pi/7), real=False)
  319. True
  320. >>> x = Symbol('x', positive=True)
  321. >>> check_assumptions(2*x + 1, positive=True)
  322. True
  323. >>> check_assumptions(-2*x - 5, positive=True)
  324. False
  325. To check assumptions of *expr* against another variable or expression,
  326. pass the expression or variable as ``against``.
  327. >>> check_assumptions(2*x + 1, x)
  328. True
  329. To see if a number matches the assumptions of an expression, pass
  330. the number as the first argument, else its specific assumptions
  331. may not have a non-None value in the expression:
  332. >>> check_assumptions(x, 3)
  333. >>> check_assumptions(3, x)
  334. True
  335. ``None`` is returned if ``check_assumptions()`` could not conclude.
  336. >>> check_assumptions(2*x - 1, x)
  337. >>> z = Symbol('z')
  338. >>> check_assumptions(z, real=True)
  339. See Also
  340. ========
  341. failing_assumptions
  342. """
  343. expr = sympify(expr)
  344. if against is not None:
  345. if assume:
  346. raise ValueError(
  347. 'Expecting `against` or `assume`, not both.')
  348. assume = assumptions(against)
  349. known = True
  350. for k, v in assume.items():
  351. if v is None:
  352. continue
  353. e = getattr(expr, 'is_' + k, None)
  354. if e is None:
  355. known = None
  356. elif v != e:
  357. return False
  358. return known
  359. class StdFactKB(FactKB):
  360. """A FactKB specialized for the built-in rules
  361. This is the only kind of FactKB that Basic objects should use.
  362. """
  363. def __init__(self, facts=None):
  364. super().__init__(_assume_rules)
  365. # save a copy of the facts dict
  366. if not facts:
  367. self._generator = {}
  368. elif not isinstance(facts, FactKB):
  369. self._generator = facts.copy()
  370. else:
  371. self._generator = facts.generator
  372. if facts:
  373. self.deduce_all_facts(facts)
  374. def copy(self):
  375. return self.__class__(self)
  376. @property
  377. def generator(self):
  378. return self._generator.copy()
  379. def as_property(fact):
  380. """Convert a fact name to the name of the corresponding property"""
  381. return 'is_%s' % fact
  382. def make_property(fact):
  383. """Create the automagic property corresponding to a fact."""
  384. def getit(self):
  385. try:
  386. return self._assumptions[fact]
  387. except KeyError:
  388. if self._assumptions is self.default_assumptions:
  389. self._assumptions = self.default_assumptions.copy()
  390. return _ask(fact, self)
  391. getit.func_name = as_property(fact)
  392. return property(getit)
  393. def _ask(fact, obj):
  394. """
  395. Find the truth value for a property of an object.
  396. This function is called when a request is made to see what a fact
  397. value is.
  398. For this we use several techniques:
  399. First, the fact-evaluation function is tried, if it exists (for
  400. example _eval_is_integer). Then we try related facts. For example
  401. rational --> integer
  402. another example is joined rule:
  403. integer & !odd --> even
  404. so in the latter case if we are looking at what 'even' value is,
  405. 'integer' and 'odd' facts will be asked.
  406. In all cases, when we settle on some fact value, its implications are
  407. deduced, and the result is cached in ._assumptions.
  408. """
  409. # FactKB which is dict-like and maps facts to their known values:
  410. assumptions = obj._assumptions
  411. # A dict that maps facts to their handlers:
  412. handler_map = obj._prop_handler
  413. # This is our queue of facts to check:
  414. facts_to_check = [fact]
  415. facts_queued = {fact}
  416. # Loop over the queue as it extends
  417. for fact_i in facts_to_check:
  418. # If fact_i has already been determined then we don't need to rerun the
  419. # handler. There is a potential race condition for multithreaded code
  420. # though because it's possible that fact_i was checked in another
  421. # thread. The main logic of the loop below would potentially skip
  422. # checking assumptions[fact] in this case so we check it once after the
  423. # loop to be sure.
  424. if fact_i in assumptions:
  425. continue
  426. # Now we call the associated handler for fact_i if it exists.
  427. fact_i_value = None
  428. handler_i = handler_map.get(fact_i)
  429. if handler_i is not None:
  430. fact_i_value = handler_i(obj)
  431. # If we get a new value for fact_i then we should update our knowledge
  432. # of fact_i as well as any related facts that can be inferred using the
  433. # inference rules connecting the fact_i and any other fact values that
  434. # are already known.
  435. if fact_i_value is not None:
  436. assumptions.deduce_all_facts(((fact_i, fact_i_value),))
  437. # Usually if assumptions[fact] is now not None then that is because of
  438. # the call to deduce_all_facts above. The handler for fact_i returned
  439. # True or False and knowing fact_i (which is equal to fact in the first
  440. # iteration) implies knowing a value for fact. It is also possible
  441. # though that independent code e.g. called indirectly by the handler or
  442. # called in another thread in a multithreaded context might have
  443. # resulted in assumptions[fact] being set. Either way we return it.
  444. fact_value = assumptions.get(fact)
  445. if fact_value is not None:
  446. return fact_value
  447. # Extend the queue with other facts that might determine fact_i. Here
  448. # we randomise the order of the facts that are checked. This should not
  449. # lead to any non-determinism if all handlers are logically consistent
  450. # with the inference rules for the facts. Non-deterministic assumptions
  451. # queries can result from bugs in the handlers that are exposed by this
  452. # call to shuffle. These are pushed to the back of the queue meaning
  453. # that the inference graph is traversed in breadth-first order.
  454. new_facts_to_check = list(_assume_rules.prereq[fact_i] - facts_queued)
  455. shuffle(new_facts_to_check)
  456. facts_to_check.extend(new_facts_to_check)
  457. facts_queued.update(new_facts_to_check)
  458. # The above loop should be able to handle everything fine in a
  459. # single-threaded context but in multithreaded code it is possible that
  460. # this thread skipped computing a particular fact that was computed in
  461. # another thread (due to the continue). In that case it is possible that
  462. # fact was inferred and is now stored in the assumptions dict but it wasn't
  463. # checked for in the body of the loop. This is an obscure case but to make
  464. # sure we catch it we check once here at the end of the loop.
  465. if fact in assumptions:
  466. return assumptions[fact]
  467. # This query can not be answered. It's possible that e.g. another thread
  468. # has already stored None for fact but assumptions._tell does not mind if
  469. # we call _tell twice setting the same value. If this raises
  470. # InconsistentAssumptions then it probably means that another thread
  471. # attempted to compute this and got a value of True or False rather than
  472. # None. In that case there must be a bug in at least one of the handlers.
  473. # If the handlers are all deterministic and are consistent with the
  474. # inference rules then the same value should be computed for fact in all
  475. # threads.
  476. assumptions._tell(fact, None)
  477. return None
  478. def _prepare_class_assumptions(cls):
  479. """Precompute class level assumptions and generate handlers.
  480. This is called by Basic.__init_subclass__ each time a Basic subclass is
  481. defined.
  482. """
  483. local_defs = {}
  484. for k in _assume_defined:
  485. attrname = as_property(k)
  486. v = cls.__dict__.get(attrname, '')
  487. if isinstance(v, (bool, int, type(None))):
  488. if v is not None:
  489. v = bool(v)
  490. local_defs[k] = v
  491. defs = {}
  492. for base in reversed(cls.__bases__):
  493. assumptions = getattr(base, '_explicit_class_assumptions', None)
  494. if assumptions is not None:
  495. defs.update(assumptions)
  496. defs.update(local_defs)
  497. cls._explicit_class_assumptions = defs
  498. cls.default_assumptions = StdFactKB(defs)
  499. cls._prop_handler = {}
  500. for k in _assume_defined:
  501. eval_is_meth = getattr(cls, '_eval_is_%s' % k, None)
  502. if eval_is_meth is not None:
  503. cls._prop_handler[k] = eval_is_meth
  504. # Put definite results directly into the class dict, for speed
  505. for k, v in cls.default_assumptions.items():
  506. setattr(cls, as_property(k), v)
  507. # protection e.g. for Integer.is_even=F <- (Rational.is_integer=F)
  508. derived_from_bases = set()
  509. for base in cls.__bases__:
  510. default_assumptions = getattr(base, 'default_assumptions', None)
  511. # is an assumption-aware class
  512. if default_assumptions is not None:
  513. derived_from_bases.update(default_assumptions)
  514. for fact in derived_from_bases - set(cls.default_assumptions):
  515. pname = as_property(fact)
  516. if pname not in cls.__dict__:
  517. setattr(cls, pname, make_property(fact))
  518. # Finally, add any missing automagic property (e.g. for Basic)
  519. for fact in _assume_defined:
  520. pname = as_property(fact)
  521. if not hasattr(cls, pname):
  522. setattr(cls, pname, make_property(fact))
  523. # XXX: ManagedProperties used to be the metaclass for Basic but now Basic does
  524. # not use a metaclass. We leave this here for backwards compatibility for now
  525. # in case someone has been using the ManagedProperties class in downstream
  526. # code. The reason that it might have been used is that when subclassing a
  527. # class and wanting to use a metaclass the metaclass must be a subclass of the
  528. # metaclass for the class that is being subclassed. Anyone wanting to subclass
  529. # Basic and use a metaclass in their subclass would have needed to subclass
  530. # ManagedProperties. Here ManagedProperties is not the metaclass for Basic any
  531. # more but it should still be usable as a metaclass for Basic subclasses since
  532. # it is a subclass of type which is now the metaclass for Basic.
  533. class ManagedProperties(type):
  534. def __init__(cls, *args, **kwargs):
  535. msg = ("The ManagedProperties metaclass. "
  536. "Basic does not use metaclasses any more")
  537. sympy_deprecation_warning(msg,
  538. deprecated_since_version="1.12",
  539. active_deprecations_target='managedproperties')
  540. # Here we still call this function in case someone is using
  541. # ManagedProperties for something that is not a Basic subclass. For
  542. # Basic subclasses this function is now called by __init_subclass__ and
  543. # so this metaclass is not needed any more.
  544. _prepare_class_assumptions(cls)