Skip to content
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

cylint: remove imports in misc/ #35697

Merged
merged 1 commit into from
Jun 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/sage/misc/binary_tree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ cdef object binary_tree_get(binary_tree_node *self, int key):

cdef object binary_tree_delete(binary_tree_node *self, int key):
cdef object t
cdef binary_tree_node *cur
if self.key > key:
if self.left == NULL:
return None
Expand Down
27 changes: 16 additions & 11 deletions src/sage/misc/fpickle.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Function pickling

REFERENCE: The python cookbook.
"""

import copyreg
import pickle
import sys
Expand Down Expand Up @@ -91,6 +90,7 @@ def pickle_function(func):
"""
return pickle.dumps(func.__code__)


def unpickle_function(pickled):
"""
Unpickle a pickled function.
Expand All @@ -106,15 +106,16 @@ def unpickle_function(pickled):
return types.FunctionType(recovered, globals())



def call_pickled_function(fpargs):
import sage.all
from sage.misc.fpickle import unpickle_function
from sage.misc.fpickle import unpickle_function # used below
(fp, (args, kwds)) = fpargs
f = eval("unpickle_function(fp)", sage.all.__dict__, {'fp':fp})
res = eval("f(*args, **kwds)",sage.all.__dict__, {'args':args, 'kwds':kwds, 'f':f})
f = eval("unpickle_function(fp)", sage.all.__dict__, {'fp': fp})
res = eval("f(*args, **kwds)", sage.all.__dict__,
{'args': args, 'kwds': kwds, 'f': f})
return ((args, kwds), res)


# The following four methods are taken from twisted.persisted.styles - the
# import of twisted.persisted.styles takes a long time and we do not use
# most functionality it provides
Expand All @@ -128,11 +129,11 @@ def pickleMethod(method):


def unpickleMethod(im_name,
__self__,
im_class):
__self__,
im_class):
'support function for copyreg to unpickle method refs'
try:
unbound = getattr(im_class,im_name)
unbound = getattr(im_class, im_name)
if __self__ is None:
return unbound

Expand All @@ -154,21 +155,25 @@ def unpickleMethod(im_name,
__self__)
return bound


copyreg.pickle(types.MethodType,
pickleMethod,
unpickleMethod)
pickleMethod,
unpickleMethod)

oldModules = {}


def pickleModule(module):
'support function for copyreg to pickle module refs'
return unpickleModule, (module.__name__,)


def unpickleModule(name):
'support function for copyreg to unpickle module refs'
if name in oldModules:
name = oldModules[name]
return __import__(name,{},{},'x')
return __import__(name, {}, {}, 'x')


copyreg.pickle(types.ModuleType,
pickleModule,
Expand Down
2 changes: 0 additions & 2 deletions src/sage/misc/misc_c.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ AUTHORS:
# https://www.gnu.org/licenses/
# ****************************************************************************

import sys

from cpython.sequence cimport *
from cpython.list cimport *
from cpython.tuple cimport *
Expand Down
4 changes: 1 addition & 3 deletions src/sage/misc/parser.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ AUTHOR:
# https://www.gnu.org/licenses/
# ***************************************************************************

from libc.string cimport strchr
from cpython.bytes cimport PyBytes_FromStringAndSize
from cpython.list cimport PyList_Append

import math
Expand Down Expand Up @@ -1095,4 +1093,4 @@ cdef class LookupNameMaker:
except KeyError:
if self.fallback is not None:
return self.fallback(name)
raise NameError("Unknown variable: '{}'".format(name))
raise NameError(f"Unknown variable: '{name}'")
2 changes: 0 additions & 2 deletions src/sage/misc/randstate.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ import os
import time
import weakref
import random as _random
import sys

use_urandom = False
# Check whether os.urandom() works.
Expand Down Expand Up @@ -713,7 +712,6 @@ cdef class randstate:
if self._gap_saved_seed is not None:
mersenne_seed, classic_seed = self._gap_saved_seed
else:
import sage.rings.integer_ring as integer_ring
from sage.rings.integer_ring import ZZ
seed = ZZ.random_element(long(1)<<128)
classic_seed = seed
Expand Down
3 changes: 1 addition & 2 deletions src/sage/misc/session.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ AUTHOR:
# Copyright (C) 2007,2010 William Stein <wstein@gmail.com>
# Distributed under the terms of the GNU General Public License (GPL)
# The full text of the GPL is available at:
# http://www.gnu.org/licenses/
# https://www.gnu.org/licenses/
#############################################################################

# Standard python imports
import builtins
import os
import types

# We want the caller's locals, but locals() is emulated in Cython
Expand Down
4 changes: 1 addition & 3 deletions src/sage/misc/weak_dict.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,13 @@ See :trac:`13394` for a discussion of some of the design considerations.
# https://www.gnu.org/licenses/
# ****************************************************************************

import weakref
from weakref import KeyedRef
from copy import deepcopy

from cpython.dict cimport PyDict_SetItem, PyDict_Next
from cpython.tuple cimport PyTuple_GET_SIZE, PyTuple_New
from cpython.weakref cimport PyWeakref_NewRef
from cpython.object cimport PyObject_Hash
from cpython.ref cimport Py_INCREF, Py_XINCREF, Py_XDECREF
from cpython.ref cimport Py_INCREF
from sage.cpython.dict_del_by_value cimport *

from sage.misc.superseded import deprecation
Expand Down