Skip to content

Commit 50776da

Browse files
author
Release Manager
committed
Trac #32757: last fixes for relint linter
namely - remove check for sagenb - remove last traces of {{{__metaclass__}}} This should allow this linter to turn green. URL: https://trac.sagemath.org/32757 Reported by: chapoton Ticket author(s): Frédéric Chapoton Reviewer(s): Matthias Koeppe
2 parents d95005e + c2cba32 commit 50776da

File tree

7 files changed

+38
-77
lines changed

7 files changed

+38
-77
lines changed

src/.relint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
hint: |
88
# ifilter, imap, izip # __metaclass__
99
Hint: # update raise statements # except Exception, var
10-
Hint: # sagenb # six is no longer allowed
11-
pattern: '(import.*[, ]ifilter|import.*[, ]imap|import.*[, ]izip|^\s*raise\s*[A-Za-z]*Error\s*,|__metaclass__|except\s*[A-Za-z]\s*,|[^_]sagenb|import six|from six import)'
10+
Hint: # six is no longer allowed
11+
pattern: '(import.*[, ]ifilter|import.*[, ]imap|import.*[, ]izip|^\s*raise\s*[A-Za-z]*Error\s*,|__metaclass__|except\s*[A-Za-z]\s*,|import six|from six import)'
1212
filePattern: .*[.](py|pyx|rst)
1313

1414
- name: 'foreign_latex: foreign commands in LaTeX'

src/sage/dynamics/arithmetic_dynamics/endPN_automorphism_group.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1790,8 +1790,9 @@ def which_group(list_of_elements):
17901790
else:
17911791
return ['A_5']
17921792

1793+
17931794
def conjugating_set_initializer(f, g):
1794-
"""
1795+
r"""
17951796
Return a conjugation invariant set together with information
17961797
to reduce the combinatorics of checking all possible conjugations.
17971798

src/sage/misc/bindable_class.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
"""
22
Bindable classes
33
"""
4-
5-
#*****************************************************************************
4+
# ****************************************************************************
65
# Copyright (C) 2012 Nicolas M. Thiery <nthiery at users.sf.net>
76
#
87
# This program is free software: you can redistribute it and/or modify
98
# it under the terms of the GNU General Public License as published by
109
# the Free Software Foundation, either version 2 of the License, or
1110
# (at your option) any later version.
12-
# http://www.gnu.org/licenses/
13-
#*****************************************************************************
14-
15-
11+
# https://www.gnu.org/licenses/
12+
# ****************************************************************************
1613
import functools
1714
from sage.misc.nested_class import NestedClassMetaclass
1815
from sage.misc.classcall_metaclass import ClasscallMetaclass
@@ -33,16 +30,12 @@ class BindableClass(metaclass=ClasscallMetaclass):
3330
Let us consider the following class ``Outer`` with a nested class ``Inner``::
3431
3532
sage: from sage.misc.nested_class import NestedClassMetaclass
36-
sage: class Outer:
37-
....: __metaclass__ = NestedClassMetaclass # just a workaround for Python misnaming nested classes
38-
....:
33+
sage: class Outer(metaclass=NestedClassMetaclass):
3934
....: class Inner:
4035
....: def __init__(self, *args):
4136
....: print(args)
42-
....:
4337
....: def f(self, *args):
4438
....: print("{} {}".format(self, args))
45-
....:
4639
....: @staticmethod
4740
....: def f_static(*args):
4841
....: print(args)
@@ -84,9 +77,7 @@ class BindableClass(metaclass=ClasscallMetaclass):
8477
:class:`BindableClass` gives this binding behavior to all its subclasses::
8578
8679
sage: from sage.misc.bindable_class import BindableClass
87-
sage: class Outer:
88-
....: __metaclass__ = NestedClassMetaclass # just a workaround for Python misnaming nested classes
89-
....:
80+
sage: class Outer(metaclass=NestedClassMetaclass):
9081
....: class Inner(BindableClass):
9182
....: " some documentation "
9283
....: def __init__(self, outer, *args):

src/sage/misc/classcall_metaclass.pyx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,10 @@ cdef class ClasscallMetaclass(NestedClassMetaclass):
217217
We now show the usage of ``__classcall_private__``::
218218
219219
sage: class FooNoInherits(object, metaclass=ClasscallMetaclass):
220-
....: __metaclass__ = ClasscallMetaclass
221220
....: @staticmethod
222221
....: def __classcall_private__(cls):
223222
....: print("calling private classcall")
224223
....: return type.__call__(cls)
225-
...
226224
sage: FooNoInherits()
227225
calling private classcall
228226
<__main__.FooNoInherits object at ...>

src/sage/misc/nested_class.pyx

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,16 @@ EXAMPLES::
4444
4545
sage: A1.A2.A3.__name__
4646
'A3'
47-
sage: A1.A2.A3 # py2
48-
<class sage.misc.nested_class.A3 at ...>
49-
sage: A1.A2.A3 # py3
47+
sage: A1.A2.A3
5048
<class 'sage.misc.nested_class.A1.A2.A3'>
5149
52-
sage: nested_pickle(A1) # py2
53-
<class sage.misc.nested_class.A1 at ...>
54-
sage: nested_pickle(A1) # py3
50+
sage: nested_pickle(A1)
5551
<class 'sage.misc.nested_class.A1'>
5652
57-
sage: A1.A2 # py2
58-
<class sage.misc.nested_class.A1.A2 at ...>
59-
sage: A1.A2 # py3
53+
sage: A1.A2
6054
<class 'sage.misc.nested_class.A1.A2'>
6155
62-
sage: A1.A2.A3 # py2
63-
<class sage.misc.nested_class.A1.A2.A3 at ...>
64-
sage: A1.A2.A3 # py3
56+
sage: A1.A2.A3
6557
<class 'sage.misc.nested_class.A1.A2.A3'>
6658
sage: A1.A2.A3.__name__
6759
'A1.A2.A3'
@@ -79,22 +71,13 @@ All of this is not perfect. In the following scenario::
7971
sage: class B1:
8072
....: A2 = A1.A2
8173
82-
sage: nested_pickle(A1) # py2
83-
<class __main__.A1 at ...>
84-
sage: nested_pickle(B1) # py2
85-
<class __main__.B1 at ...>
86-
sage: A1.A2 # py2
87-
<class __main__.A1.A2 at ...>
88-
sage: B1.A2 # py2
89-
<class __main__.A1.A2 at ...>
90-
91-
sage: nested_pickle(A1) # py3
74+
sage: nested_pickle(A1)
9275
<class '__main__.A1'>
93-
sage: nested_pickle(B1) # py3
76+
sage: nested_pickle(B1)
9477
<class '__main__.B1'>
95-
sage: A1.A2 # py3
78+
sage: A1.A2
9679
<class '__main__.A1.A2'>
97-
sage: B1.A2 # py3
80+
sage: B1.A2
9881
<class '__main__.A1.A2'>
9982
10083
The name for ``"A1.A2"`` could potentially be set to ``"B1.A2"``. But that will work anyway.
@@ -161,14 +144,9 @@ cpdef modify_for_nested_pickle(cls, str name_prefix, module, first_run=True):
161144
Note that the class is now found in the module under both its old and
162145
its new name::
163146
164-
sage: getattr(module, 'A.B', 'Not found') # py2
165-
<class '__main__.X.A.B'>
166-
sage: getattr(module, 'X.A.B', 'Not found') # py2
167-
<class '__main__.X.A.B'>
168-
169-
sage: getattr(module, 'A.B', 'Not found') # py3
147+
sage: getattr(module, 'A.B', 'Not found')
170148
<class '__main__.A.B'>
171-
sage: getattr(module, 'X.A.B', 'Not found') # py3
149+
sage: getattr(module, 'X.A.B', 'Not found')
172150
<class '__main__.A.B'>
173151
174152
TESTS:
@@ -253,9 +231,7 @@ def nested_pickle(cls):
253231
254232
sage: A.B.__name__
255233
'A.B'
256-
sage: getattr(module, 'A.B', 'Not found') # py2
257-
<class __main__.A.B at ...>
258-
sage: getattr(module, 'A.B', 'Not found') # py3
234+
sage: getattr(module, 'A.B', 'Not found')
259235
<class '__main__.A.B'>
260236
261237
In Python 2.6, decorators work with classes; then ``@nested_pickle``
@@ -288,10 +264,8 @@ cdef class NestedClassMetaclass(type):
288264
derived subclass::
289265
290266
sage: from sage.misc.nested_class import NestedClassMetaclass
291-
sage: class ASuperClass(object): # py2
292-
....: __metaclass__ = NestedClassMetaclass # py2
293-
sage: class ASuperClass(object, metaclass=NestedClassMetaclass): # py3
294-
....: pass # py3
267+
sage: class ASuperClass(object, metaclass=NestedClassMetaclass):
268+
....: pass
295269
sage: class A3(ASuperClass):
296270
....: class B(object):
297271
....: pass
@@ -304,16 +278,16 @@ cdef class NestedClassMetaclass(type):
304278
r"""
305279
This invokes the nested_pickle on construction.
306280
307-
sage: from sage.misc.nested_class import NestedClassMetaclass
308-
sage: class A(object):
309-
....: __metaclass__ = NestedClassMetaclass
310-
....: class B(object):
311-
....: pass
312-
...
313-
sage: A.B
314-
<class '__main__.A.B'>
315-
sage: getattr(sys.modules['__main__'], 'A.B', 'Not found')
316-
<class '__main__.A.B'>
281+
EXAMPLES::
282+
283+
sage: from sage.misc.nested_class import NestedClassMetaclass
284+
sage: class A(object, metaclass=NestedClassMetaclass):
285+
....: class B(object):
286+
....: pass
287+
sage: A.B
288+
<class '__main__.A.B'>
289+
sage: getattr(sys.modules['__main__'], 'A.B', 'Not found')
290+
<class '__main__.A.B'>
317291
"""
318292
modify_for_nested_pickle(self, self.__name__, sys_modules[self.__module__])
319293

src/sage/misc/sageinspect.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ def loadable_module_extension():
192192

193193
def isclassinstance(obj):
194194
r"""
195-
Checks if argument is instance of non built-in class
195+
Check if argument is instance of non built-in class
196196
197-
INPUT: ``obj`` - object
197+
INPUT: ``obj`` -- object
198198
199199
EXAMPLES::
200200
@@ -207,12 +207,10 @@ def isclassinstance(obj):
207207
sage: isclassinstance(myclass)
208208
False
209209
sage: class mymetaclass(type): pass
210-
sage: class myclass2:
211-
....: __metaclass__ = mymetaclass
210+
sage: class myclass2(metaclass=mymetaclass): pass
212211
sage: isclassinstance(myclass2)
213212
False
214213
"""
215-
216214
builtin_mods = set(['__builtin__', 'builtins', 'exceptions'])
217215

218216
return (not inspect.isclass(obj) and
@@ -1630,7 +1628,7 @@ def foo(x, a='\')"', b={not (2+1==3):'bar'}): return
16301628
except (TypeError, AttributeError):
16311629
pass
16321630
if isclassinstance(obj):
1633-
if hasattr(obj,'_sage_src_'): #it may be a decorator!
1631+
if hasattr(obj, '_sage_src_'): #it may be a decorator!
16341632
source = sage_getsource(obj)
16351633
try:
16361634
# we try to find the definition and parse it by
@@ -2384,7 +2382,7 @@ class Element(object):
23842382

23852383
# Check if we deal with an instance
23862384
if isclassinstance(obj):
2387-
if isinstance(obj,functools.partial):
2385+
if isinstance(obj, functools.partial):
23882386
return sage_getsourcelines(obj.func)
23892387
else:
23902388
return sage_getsourcelines(obj.__class__)

src/sage_docbuild/ext/sage_autodoc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,8 +1174,7 @@ def import_object(self):
11741174
# by using the metaclass NestedMetaclass, we change the attribute
11751175
# __name__ of the nested class. For example, in
11761176
#
1177-
# class A:
1178-
# __metaclass__ = NestedClassMetaclass
1177+
# class A(metaclass=NestedMetaclass):
11791178
# class B(object):
11801179
# pass
11811180
#

0 commit comments

Comments
 (0)