-
-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sage.geometry.abc; remove uses of is_Polyhedron, is_LatticePolytope, is_Cone outside of sage.geometry #32637
Comments
Author: Matthias Koeppe |
New commits:
|
Commit: |
This comment has been minimized.
This comment has been minimized.
comment:5
I worry that we're changing On the other hand, you don't want to put the implementation into the base class, because the whole point is to avoid importing the implementations to perform a typecheck. Nor does it make much sense to blindly add a million I wonder if something ridiculous like this wouldn't also work as an interim hack:
You can also check the (string) module name with |
comment:6
Replying to @orlitzky:
As explained in #32414, "each of the new abstract base classes is intended to have a unique direct implementation subclass. Attempting to define new hierarchies of abstract base classes is beyond the scope of this ticket. Also, the new classes do not define any methods.". |
comment:7
Replying to @orlitzky:
Yeah, I'm not interested in a solution that looks like this |
comment:8
Replying to @mkoeppe:
I saw that, but unless you plan to live forever and spend most of it monitoring trac, there's no technical means to enforce that restriction. |
comment:9
Sounds like someone wants to write a decorator for these types of classes |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:11
Replying to @mkoeppe:
I don't know how to do it with a decorator, but I think a metaclass can ensure that a given class is only subclassed once. As an added bonus, the metaclass can explain why these exist and how they should be used (i.e. that they aren't really abstract base classes). This example fails (as intended) the second time we subclass: class TypeCheckWrapper(type):
_subclasses = 0
def __init__(cls, name, bases, clsdict):
if len(cls.mro()) > 2:
TypeCheckWrapper._subclasses += 1
if TypeCheckWrapper._subclasses > 1:
raise TypeError("TypeCheckWrapper with multiple subclasses")
super(TypeCheckWrapper, cls).__init__(name, bases, clsdict)
class Polyhedron(metaclass=TypeCheckWrapper):
pass
print("Defined base class Polyhedron")
class Cone(Polyhedron):
pass
print("Defined class Cone(Polyhedron)")
class Polytope(Polyhedron):
pass
print("Defined class Polytope(Polyhedron)") |
comment:12
I think this discussion should go to a separate ticket. Note also that some of the ABCs added in other tickets of #32414 are actually extension classes, and using a metaclass there is probably tricky. |
comment:13
A simple solution could be to just add a doctest for the MRO length. We enforce pretty much everything else with doctests as well. |
comment:14
|
Dependencies: #32614 |
Branch pushed to git repo; I updated commit sha1. Last 10 new commits:
|
comment:17
How's this? |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
Branch pushed to git repo; I updated commit sha1. Last 10 new commits:
|
comment:21
We actually have a module ( Using doctests is good enough. |
Reviewer: Michael Orlitzky |
comment:22
Thanks! |
In this ticket, we add ABCs
LatticePolytope
,ConvexRationalPolyhedralCone
,Polyhedron
.A small number of uses outside of
sage.geometry
will need updating.$ git grep 'geometry.*import.*is_[A-Z]' src/sage/
(Part of meta-ticket #32414)
Depends on #32614
Depends on #32649
CC: @kliem @orlitzky @egourgoulhon
Component: refactoring
Author: Matthias Koeppe
Branch/Commit:
44540f5
Reviewer: Michael Orlitzky
Issue created by migration from https://trac.sagemath.org/ticket/32637
The text was updated successfully, but these errors were encountered: