Skip to content

Commit

Permalink
use-statements-part3 (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
rinarakaki committed Nov 1, 2023
1 parent d1c2e1d commit 66310b8
Show file tree
Hide file tree
Showing 110 changed files with 383 additions and 416 deletions.
2 changes: 1 addition & 1 deletion Cython/Compiler/Code.pxd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# cython: language_level=3

use cython
from ..StringIOTree cimport StringIOTree
use super::super::StringIOTree::StringIOTree

cdef class UtilityCodeBase(object):
cpdef format_code(self, code_string, replace_empty_lines=*)
Expand Down
2 changes: 1 addition & 1 deletion Cython/Compiler/FlowControl.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use cython

from .Visitor cimport CythonTransform, TreeVisitor
use super::Visitor::(CythonTransform, TreeVisitor)

cdef class ControlBlock:
pub set children
Expand Down
5 changes: 3 additions & 2 deletions Cython/Compiler/ParseTreeTransforms.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

use cython

from .Visitor cimport (
use super::Visitor::(
CythonTransform, VisitorTransform, TreeVisitor,
ScopeTrackingTransform, EnvTransform)
ScopeTrackingTransform, EnvTransform
)

# Don't include mixins, only the main classes.
#cdef class SkipDeclarations:
Expand Down
2 changes: 1 addition & 1 deletion Cython/Compiler/Parsing.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import absolute_import

use cython
from .Scanning cimport PyrexScanner
use super::Scanning::PyrexScanner

ctypedef object (*p_sub_expr_func)(PyrexScanner obj)

Expand Down
13 changes: 9 additions & 4 deletions Cython/Compiler/Parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1758,12 +1758,12 @@ def p_use_statement(s):
items.append(p_path(s, as_allowed=1))
stats = []
is_absolute = Future.absolute_import in s.context.future_directives
for pos, path, idents in items:
if path:
for pos, path, idents, level in items:
if len(path) > 0 or level > 0:
stat = Nodes.FromCImportStatNode(
pos,
module_name=s.context.intern_ustring(".".join(path)),
relative_level=0,
relative_level=level,
imported_names=idents,
)
else:
Expand Down Expand Up @@ -1899,6 +1899,11 @@ def p_imported_name(s):

def p_path(s, as_allowed):
pos = s.position()
level = 0
while s.sy == "IDENT" and s.systring == "super":
level += 1
s.next()
s.expect("::")
path = [p_ident(s)]
idents = []
while s.sy == "::":
Expand All @@ -1920,7 +1925,7 @@ def p_path(s, as_allowed):
path.append(p_ident(s))
if len(idents) == 0:
path, idents = path[:-1], [(s.position(), path[-1], p_as_name(s))]
return (pos, path, idents)
return (pos, path, idents, level)


def p_dotted_name(s, as_allowed):
Expand Down
2 changes: 1 addition & 1 deletion Cython/Compiler/Scanning.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cython

from ..Plex.Scanners cimport Scanner
use super::super::Plex::Scanners::Scanner

cdef unicode any_string_prefix, IDENT

Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/bytearray.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":
fn bint PyByteArray_Check(object o)
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/bytes.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":
struct va_list
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/cellobject.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":

Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/conversion.pxd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# From https://docs.python.org/3/c-api/conversion.html

from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":
struct va_list
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/descr.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject, PyTypeObject
use super::object::(PyObject, PyTypeObject)

extern from "Python.h":
ctypedef object (*wrapperfunc)(self, args, void* wrapped)
Expand Down
4 changes: 2 additions & 2 deletions Cython/Includes/cpython/dict.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .object cimport PyObject
from .pyport cimport uint64_t
use super::object::PyObject
use super::pyport::uint64_t

extern from "Python.h":
# On Python 2, PyDict_GetItemWithError is called _PyDict_GetItemWithError
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/exc.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":
#####################################################################
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/function.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":
############################################################################
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/genobject.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .pystate cimport PyFrameObject
use super::pystate::PyFrameObject

extern from "Python.h":
###########################################################################
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/list.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":
############################################################################
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/method.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":
############################################################################
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/module.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":
struct _inittab
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/number.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":
#####################################################################
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/pylifecycle.pxd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Interfaces to configure, query, create & destroy the Python runtime

use libc::stdio::FILE
from .pystate cimport PyThreadState
use super::pystate::PyThreadState

extern from "Python.h":
ctypedef i32 wchar_t
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/pystate.pxd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Thread and interpreter state structures and their interfaces

from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":
# We make these an opaque types. If the user wants specific attributes,
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/ref.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject, PyTypeObject, Py_TYPE # legacy imports for re-export
use super::object::(PyObject, PyTypeObject, Py_TYPE) # legacy imports for re-export

extern from "Python.h":
#####################################################################
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/sequence.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":
############################################################################
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/string.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":
struct va_list
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/time.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern from "Python.h":
_PyTime_t _PyTime_GetSystemClock() nogil
fn f64 _PyTime_AsSecondsDouble(_PyTime_t t) nogil

from libc.time cimport (
use libc::time::(
tm,
time_t,
localtime as libc_localtime,
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/tuple.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":
############################################################################
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/cpython/weakref.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .object cimport PyObject
use super::object::PyObject

extern from "Python.h":
fn bint PyWeakref_Check(object ob)
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/libcpp/map.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .utility cimport pair
use super::utility::pair

extern from "<map>" namespace "std" nogil:
cdef cppclass map[T, U, COMPARE=*, ALLOCATOR=*]:
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/libcpp/memory.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from libcpp cimport bool, nullptr_t, nullptr
use libcpp::(bool, nullptr_t, nullptr)

extern from "<memory>" namespace "std" nogil:
cdef cppclass default_delete[T]:
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/libcpp/pair.pxd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .utility cimport pair
use super::utility::pair
2 changes: 1 addition & 1 deletion Cython/Includes/libcpp/set.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .utility cimport pair
use super::utility::pair

extern from "<set>" namespace "std" nogil:
cdef cppclass set[T]:
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/libcpp/typeindex.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use libcpp::bool
from .typeinfo cimport type_info
use super::typeinfo::type_info

# This class is C++11-only
extern from "<typeindex>" namespace "std" nogil:
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/libcpp/unordered_map.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .utility cimport pair
use super::utility::pair

extern from "<unordered_map>" namespace "std" nogil:
cdef cppclass unordered_map[T, U, HASH=*, PRED=*, ALLOCATOR=*]:
Expand Down
2 changes: 1 addition & 1 deletion Cython/Includes/libcpp/unordered_set.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .utility cimport pair
use super::utility::pair

extern from "<unordered_set>" namespace "std" nogil:
cdef cppclass unordered_set[T,HASH=*,PRED=*,ALLOCATOR=*]:
Expand Down
4 changes: 2 additions & 2 deletions Cython/Includes/posix/select.pxd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_select.h.html

from .types cimport sigset_t
from .time cimport timeval, timespec
use super::time::(timeval, timespec)
use super::types::sigset_t

extern from "<sys/select.h>" nogil:
struct fd_set:
Expand Down
5 changes: 2 additions & 3 deletions Cython/Includes/posix/stat.pxd
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/stat.h.html
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html

from posix.types cimport (blkcnt_t, blksize_t, dev_t, gid_t, ino_t, mode_t,
nlink_t, off_t, time_t, uid_t)
use posix::time::timespec

use posix::types::(blkcnt_t, blksize_t, dev_t, gid_t, ino_t, mode_t,
nlink_t, off_t, time_t, uid_t)

extern from "<sys/stat.h>" nogil:
struct struct_stat "stat":
Expand Down
4 changes: 2 additions & 2 deletions Cython/Plex/DFA.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use cython

from . cimport Machines
from .Transitions cimport TransitionMap
use super::Machines
use super::Transitions::TransitionMap


#[cython.final]
Expand Down
4 changes: 2 additions & 2 deletions Cython/Plex/Machines.pxd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cython

from .Actions cimport Action
from .Transitions cimport TransitionMap
use super::Actions::Action
use super::Transitions::TransitionMap

cdef i32 maxint

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/tutorial/cdef_classes/integrate.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sin_of_square cimport Function, SinOfSquareFunction
use sin_of_square::(Function, SinOfSquareFunction)

def integrate(Function f, f64 a, f64 b, i32 N):
let i32 i
Expand Down
2 changes: 1 addition & 1 deletion tests/broken/cimportfunc.pyx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from cexportfunc cimport f, g
use cexportfunc::(f, g)
2 changes: 1 addition & 1 deletion tests/build/build_ext_cython_cplus.srctree
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ setup(

######## a.pyx ########

from libcpp.vector cimport vector
use libcpp::vector::vector

def use_vector(L):
try:
Expand Down
2 changes: 1 addition & 1 deletion tests/build/cpp_cythonize.srctree
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ setup(

# distutils: language=c++

from libcpp.vector cimport vector
use libcpp::vector::vector

def use_vector(L):
try:
Expand Down
13 changes: 6 additions & 7 deletions tests/build/cythonize_options.srctree
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ old_stderr = sys.stderr
captured = sys.stderr = StringIO()
try:
setup(
ext_modules = cythonize(
"*.pyx", include_path=['subdir'],
compiler_directives={'cdivision': True},
show_all_warnings=True,
),
ext_modules = cythonize(
"*.pyx", include_path=['subdir'],
compiler_directives={'cdivision': True},
show_all_warnings=True,
),
)
output = sys.stderr.getvalue()
finally:
Expand All @@ -32,14 +32,13 @@ finally:

assert "Unraisable exception in function" in output, output


######## subdir/x.pxd ########

######## subdir/y.pxi ########

######## a.pyx ########

cimport x
use x
include "y.pxi"

# cdivision from setup.py
Expand Down

0 comments on commit 66310b8

Please sign in to comment.