Completed
Push — doc-style ( 67e2d5 )
by Kyle
01:41
created

Image._init()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
1
"""This module focuses on improvements to the Python libtcod API.
2
"""
3
from __future__ import absolute_import as _
4
5
import os as _os
0 ignored issues
show
Unused Code introduced by
Unused os imported as _os
Loading history...
6
import sys as _sys
7
8
import platform as _platform
0 ignored issues
show
Unused Code introduced by
Unused platform imported as _platform
Loading history...
9
import weakref as _weakref
10
import functools as _functools
11
12
from tcod.libtcod import lib, ffi
13
14
def _unpack_char_p(char_p):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
15
    if char_p == ffi.NULL:
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named NULL.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
16
        return ''
17
    return ffi.string(char_p).decode()
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named string.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
18
19
def _int(int_or_str):
20
    'return an integer where a single character string may be expected'
21
    if isinstance(int_or_str, str):
22
        return ord(int_or_str)
23
    if isinstance(int_or_str, bytes):
24
        return int_or_str[0]
25
    return int(int_or_str) # check for __count__
26
27
def _cdata(cdata):
28
    """covert value into a cffi.CData instance"""
29
    try: # first check for _CDataWrapper
30
        cdata = cdata.cdata
31
    except AttributeError: # assume cdata is valid
0 ignored issues
show
Unused Code introduced by
This except handler seems to be unused and could be removed.

Except handlers which only contain pass and do not have an else clause can usually simply be removed:

try:
    raises_exception()
except:  # Could be removed
    pass
Loading history...
32
        pass
33
    except KeyError:
0 ignored issues
show
Unused Code introduced by
This except handler seems to be unused and could be removed.

Except handlers which only contain pass and do not have an else clause can usually simply be removed:

try:
    raises_exception()
except:  # Could be removed
    pass
Loading history...
34
        pass
35
    if cdata is None or cdata == 0: # convert None to NULL
36
        cdata = ffi.NULL
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named NULL.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
37
    return cdata
38
39
if _sys.version_info[0] == 2: # Python 2
40
    def _bytes(string):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
41
        if isinstance(string, unicode):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'unicode'
Loading history...
42
            return string.encode()
43
        return string
44
45
    def _unicode(string):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
46
        if not isinstance(string, unicode):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'unicode'
Loading history...
47
            return string.decode()
48
        return string
49
50
else: # Python 3
51
    def _bytes(string):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
52
        if isinstance(string, str):
53
            return string.encode()
54
        return string
55
56
    def _unicode(string):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
57
        if isinstance(string, bytes):
58
            return string.decode()
59
        return string
60
61
class _PropagateException():
62
    """ context manager designed to propagate exceptions outside of a cffi
63
    callback context.  normally cffi suppresses the exception
64
65
    when propagate is called this class will hold onto the error until the
66
    control flow leaves the context, then the error will be raised
67
68
    with _PropagateException as propagate:
69
    # give propagate as onerror parameter for ffi.def_extern
70
    """
71
72
    def __init__(self):
73
        self.exc_info = None # (exception, exc_value, traceback)
74
75
    def propagate(self, *exc_info):
76
        """ set an exception to be raised once this context exits
77
78
        if multiple errors are caught, only keep the first exception raised
79
        """
80
        if not self.exc_info:
81
            self.exc_info = exc_info
82
83
    def __enter__(self):
84
        """ once in context, only the propagate call is needed to use this
85
        class effectively
86
        """
87
        return self.propagate
88
89
    def __exit__(self, type, value, traceback):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
90
        """ if we're holding on to an exception, raise it now
91
92
        prefers our held exception over any current raising error
93
94
        self.exc_info is reset now in case of nested manager shenanigans
95
        """
96
        if self.exc_info:
97
            type, value, traceback = self.exc_info
0 ignored issues
show
Bug introduced by
The tuple unpacking with sequence seems to be unbalanced; 3 value(s) for 0 label(s)

This happens when the amount of values does not equal the amount of labels:

a, b = ("a", "b", "c")  # only 2 labels for 3 values
Loading history...
Bug Best Practice introduced by
It seems like you are trying to unpack a non-sequence, which was defined at line 73.
Loading history...
Bug Best Practice introduced by
It seems like you are trying to unpack a non-sequence, which was defined at line 98.
Loading history...
98
            self.exc_info = None
99
        if type:
100
            # Python 2/3 compatible throw
101
            exception = type(value)
102
            exception.__traceback__ = traceback
103
            raise exception
104
105
class _CDataWrapper(object):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
106
107
    def __init__(self, *args, **kargs):
108
        self.cdata = self._get_cdata_from_args(*args, **kargs)
109
        if self.cdata == None:
110
            self.cdata = ffi.NULL
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named NULL.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
111
        super(_CDataWrapper, self).__init__()
112
113
    def _get_cdata_from_args(self, *args, **kargs):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
114
        if len(args) == 1 and isinstance(args[0], ffi.CData) and not kargs:
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named CData.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
115
            return args[0]
116
        else:
117
            return None
118
119
120
    def __hash__(self):
121
        return hash(self.cdata)
122
123
    def __eq__(self, other):
124
        try:
125
            return self.cdata == other.cdata
126
        except AttributeError:
127
            return NotImplemented
128
129
    def __getattr__(self, attr):
130
        if 'cdata' in self.__dict__:
131
            return getattr(self.__dict__['cdata'], attr)
132
        raise AttributeError(attr)
133
134
    def __setattr__(self, attr, value):
135
        if hasattr(self, 'cdata') and hasattr(self.cdata, attr):
136
            setattr(self.cdata, attr, value)
137
        else:
138
            super(_CDataWrapper, self).__setattr__(attr, value)
139
140
def _assert_cdata_is_not_null(func):
141
    """Any BSP methods which use a cdata object in a TCOD call need to have
142
    a sanity check, otherwise it may end up passing a NULL pointer"""
143
    if __debug__:
144
        @_functools.wraps(func)
145
        def check_sanity(*args, **kargs):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable check_sanity seems to be unused.
Loading history...
146
            assert self.cdata != ffi.NULL and self.cdata is not None, \
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'self'
Loading history...
Bug introduced by
The Instance of _MockFFI does not seem to have a member named NULL.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
147
                   'cannot use function, cdata is %r' % self.cdata
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'self'
Loading history...
148
            return func(*args, **kargs)
149
    return func
150
151
class BSP(_CDataWrapper):
152
    """
153
154
    .. attribute:: x
155
    .. attribute:: y
156
    .. attribute:: w
157
    .. attribute:: h
158
159
    :param int x: rectangle left coordinate
160
    :param int y: rectangle top coordinate
161
    :param int w: rectangle width
162
    :param int h: rectangle height
163
164
    .. versionchanged:: 2.0
165
       You can create BSP's with this class contructor instead of using
166
       :any:`bsp_new_with_size`.
167
168
    """
169
170
    def __init__(self, *args, **kargs):
171
        self._reference = None # to prevent garbage collection
172
        self._children = _weakref.WeakSet() # used by _invalidate_children
173
        super(BSP, self).__init__(*args, **kargs)
174
        if self._get_cdata_from_args(*args, **kargs) is None:
175
            self._init(*args, **kargs)
176
177
    def _init(self, x, y, w, h):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
178
        self.cdata = ffi.gc(lib.TCOD_bsp_new_with_size(x, y, w, h),
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named gc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of object does not seem to have a member named TCOD_bsp_new_with_size.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
179
                             lib.TCOD_bsp_delete)
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_bsp_delete.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
180
181
    def _pass_reference(self, reference):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
182
        self._reference = reference
183
        self._reference._children.add(self)
184
        return self
185
186
    def _invalidate_children(self):
187
        """Invalidates BSP instances known to be based off of this one."""
188
        for child in self._children:
189
            child._reference = None
190
            child._invalidate_children()
191
            child.cdata = ffi.NULL
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named NULL.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
192
        self._children.clear()
193
194
    def __repr__(self):
195
        """Provide a useful readout when printed."""
196
        if not self.cdata:
197
            return '<%s NULL!>' % self.__class__.__name__
198
199
        status = 'leaf'
200
        if not self.is_leaf():
201
            status = ('split at dicision=%i,orientation=%r' %
202
                      (self.get_division(), self.get_orientation()))
203
204
        return ('<%s(x=%i,y=%i,w=%i,h=%i)depth=%i,%s>' %
205
                (self.__class__.__name__,
206
                 self.x, self.y, self.w, self.h, self.get_depth(), status))
207
208
    def get_depth(self):
209
        """Return the depth of this node.
210
211
        :rtype: int
212
213
        .. versionadded:: 2.0
214
        """
215
        return self.cdata.level
216
217
    def get_division(self):
218
        """Return the point where this node was divided into parts.
219
220
        :rtype: :any:`int` or :any:`None`
221
222
        .. versionadded:: 2.0
223
        """
224
        if self.is_leaf():
225
            return None
226
        return self.cdata.position
227
228
    def get_orientation(self):
229
        """
230
231
        :rtype: str
232
233
        .. versionadded:: 2.0
234
        """
235
        if self.is_leaf():
236
            return ''
237
        elif self.cdata.horizontal:
238
            return 'horizontal'
239
        else:
240
            return 'vertical'
241
242
    @_assert_cdata_is_not_null
243
    def split_once(self, orientation, position):
244
        """
245
246
        :rtype: tuple
247
248
        .. versionadded:: 2.0
249
        """
250
        # orientation = horz
251
        if orientation[:1].lower() == 'h':
252
            lib.TCOD_bsp_split_once(self.cdata, True, position)
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_bsp_split_once.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
253
        elif orientation[:1].lower() == 'v':
254
            lib.TCOD_bsp_split_once(self.cdata, False, position)
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_bsp_split_once.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
255
        else:
256
            raise ValueError("orientation must be 'horizontal' or 'vertical'"
257
                             "\nNot %r" % orientation)
258
        return self.get_children()
259
260
    @_assert_cdata_is_not_null
261
    def split_recursive(self, depth, min_width, min_height,
262
                        max_horz_ratio, max_vert_raito, random=None):
263
        """
264
265
        :rtype: iter
266
267
        .. versionadded:: 2.0
268
        """
269
        lib.TCOD_bsp_split_recursive(self.cdata, random or ffi.NULL,
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_bsp_split_recursive.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of _MockFFI does not seem to have a member named NULL.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
270
                                      depth, min_width, min_height,
271
                                      max_horz_ratio, max_vert_raito)
272
        return self.walk()
273
274
    @_assert_cdata_is_not_null
275
    def resize(self, x, y, w, h):
276
        """Resize this BSP to the provided rectangle.
277
278
        :param int x: rectangle left coordinate
279
        :param int y: rectangle top coordinate
280
        :param int w: rectangle width
281
        :param int h: rectangle height
282
283
        .. versionadded:: 2.0
284
        """
285
        lib.TCOD_bsp_resize(self.cdata, x, y, w, h)
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_bsp_resize.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
286
287
    @_assert_cdata_is_not_null
288
    def get_left(self):
289
        """Return this BSP's 'left' child.
290
291
        Returns None if this BSP is a leaf node.
292
293
        :return: BSP's left/top child or None.
294
        :rtype: :any:`BSP` or :any:`None`
295
296
        .. versionadded:: 2.0
297
        """
298
        if self.is_leaf():
299
            return None
300
        return BSP(lib.TCOD_bsp_left(self.cdata))._pass_reference(self)
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_bsp_left.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
301
302
    @_assert_cdata_is_not_null
303
    def get_right(self):
304
        """Return this BSP's 'right' child.
305
306
        Returns None if this BSP is a leaf node.
307
308
        :return: BSP's right/bottom child or None.
309
        :rtype: :any:`BSP` or :any:`None`
310
311
        .. versionadded:: 2.0
312
        """
313
        if self.is_leaf():
314
            return None
315
        return BSP(lib.TCOD_bsp_right(self.cdata))._pass_reference(self)
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_bsp_right.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
316
317
    @_assert_cdata_is_not_null
318
    def get_parent(self):
319
        """Return this BSP's parent node.
320
321
        :return: Returns the parent node as a BSP instance.
322
                 Returns None if this BSP has no parent.
323
        :rtype: :any:`BSP` or :any:`None`
324
325
        .. versionadded:: 2.0
326
        """
327
        node = BSP(lib.TCOD_bsp_father(self.cdata))._pass_reference(self)
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_bsp_father.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
328
        if node.cdata == ffi.NULL:
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named NULL.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
329
            return None
330
        return node
331
332
    @_assert_cdata_is_not_null
333
    def get_children(self):
334
        """Return as a tuple, this instances immediate children, if any.
335
336
        :return: Returns a tuple of (left, right) BSP instances.
337
                 The returned tuple is empty if this BSP has no children.
338
        :rtype: tuple
339
340
        .. versionadded:: 2.0
341
        """
342
        if self.is_leaf():
343
            return ()
344
        return (BSP(lib.TCOD_bsp_left(self.cdata))._pass_reference(self),
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_bsp_left.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
345
                BSP(lib.TCOD_bsp_right(self.cdata))._pass_reference(self))
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_bsp_right.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
346
347
    @_assert_cdata_is_not_null
348
    def walk(self):
349
        """Iterate over this BSP's hieracrhy.
350
351
        The iterator will include the instance which called it.
352
        It will traverse its own children and grandchildren, in no particular
353
        order.
354
355
        :return: Returns an iterator of BSP instances.
356
        :rtype: iter
357
358
        .. versionadded:: 2.0
359
        """
360
        for child in self.get_children():
361
            for grandchild in child.walk():
362
                yield grandchild
363
        yield self
364
365
    @_assert_cdata_is_not_null
366
    def is_leaf(self):
367
        """Returns True if this node is a leaf.  False when this node has children.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (83/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
368
369
        :rtype: bool
370
371
        .. versionadded:: 2.0
372
        """
373
        return bool(lib.TCOD_bsp_is_leaf(self.cdata))
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_bsp_is_leaf.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
374
375
    @_assert_cdata_is_not_null
376
    def contains(self, x, y):
377
        """Returns True if this node contains these coordinates.
378
379
        :rtype: bool
380
381
        .. versionadded:: 2.0
382
        """
383
        return bool(lib.TCOD_bsp_contains(self.cdata, x, y))
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_bsp_contains.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
384
385
    @_assert_cdata_is_not_null
386
    def find_node(self, x, y):
387
        """Return the deepest node which contains these coordinates.
388
389
        :rtype: :any:`BSP` or :any:`None`
390
391
        .. versionadded:: 2.0
392
        """
393
        node = BSP(lib.TCOD_bsp_find_node(self.cdata,
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_bsp_find_node.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
394
                                           x, y))._pass_reference(self)
395
        if node.cdata == ffi.NULL:
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named NULL.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
396
            node = None
397
        return node
398
399
class HeightMap(_CDataWrapper):
400
    """libtcod HeightMap instance
401
    """
402
403
    def __init__(self, *args, **kargs):
404
        super(HeightMap, self).__init__(*args, **kargs)
405
        if not self.cdata:
406
            self._init(*args, **kargs)
407
408
    def _init(self, width, height):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
409
        self.cdata = ffi.gc(lib.TCOD_heightmap_new(width, height),
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named gc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of object does not seem to have a member named TCOD_heightmap_new.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
410
                            lib.TCOD_heightmap_delete)
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_heightmap_delete.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
411
412
413
class Key(_CDataWrapper):
414
    """Key Event instance
415
    """
416
417
    def __init__(self, *args):
418
        super(Key, self).__init__(*args)
419
        if self.cdata == ffi.NULL:
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named NULL.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
420
            self.cdata = ffi.new('TCOD_key_t*')
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named new.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
421
422
    def __getattr__(self, attr):
423
        if attr == 'c':
424
            return ord(getattr(self.cdata, attr))
425
        else:
426
            return super(Key, self).__getattr__(attr)
427
428
class Mouse(_CDataWrapper):
429
    """Mouse event instance
430
    """
431
432
    def __init__(self, *args):
433
        super(Mouse, self).__init__(*args)
434
        if self.cdata == ffi.NULL:
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named NULL.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
435
            self.cdata = ffi.new('TCOD_mouse_t*')
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named new.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
436
437
438
class Console(_CDataWrapper):
439
    """
440
441
    .. versionadded:: 2.0
442
    """
443
444
    def __init__(self, *args, **kargs):
0 ignored issues
show
Bug introduced by
The __init__ method of the super-class _CDataWrapper is not called.

It is generally advisable to initialize the super-class by calling its __init__ method:

class SomeParent:
    def __init__(self):
        self.x = 1

class SomeChild(SomeParent):
    def __init__(self):
        # Initialize the super class
        SomeParent.__init__(self)
Loading history...
445
        self.cdata = self._get_cdata_from_args(*args, **kargs)
446
        if self.cdata is None:
447
            self._init(*args, **kargs)
448
449
    def _init(self, width, height):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
450
        self.cdata = ffi.gc(lib.TCOD_console_new(width, height),
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named gc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of object does not seem to have a member named TCOD_console_new.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
451
                            lib.TCOD_console_delete)
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_console_delete.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
452
453
class Image(_CDataWrapper):
454
    """
455
456
    .. versionadded:: 2.0
457
    """
458
    def __init__(self, *args, **kargs):
459
        super(Console, self).__init__(*args, **kargs)
0 ignored issues
show
Bug introduced by
The first argument passed to super() should be the super-class name, but Console was given.
Loading history...
460
        if not self.cdata:
461
            self._init(*args, **kargs)
462
463
    def _init(self, width, height):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
464
        self.cdata = ffi.gc(lib.TCOD_image_new(width, height),
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named gc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of object does not seem to have a member named TCOD_image_new.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
465
                            lib.TCOD_image_delete)
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_image_delete.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
466
467
def clipboard_set(string):
468
    """Set the clipboard contents to string.
469
470
    .. versionadded:: 2.0
471
    """
472
    lib.TCOD_sys_clipboard_set(_bytes(string))
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_sys_clipboard_set.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
473
474
def clipboard_get():
475
    """Return the current contents of the clipboard.
476
477
    .. versionadded:: 2.0
478
    """
479
    return _unpack_char_p(lib.TCOD_sys_clipboard_get())
0 ignored issues
show
Bug introduced by
The Instance of object does not seem to have a member named TCOD_sys_clipboard_get.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
480
481
@ffi.def_extern()
482
def _pycall_bsp_callback(node, handle):
483
    """static bool _pycall_bsp_callback(TCOD_bsp_t *node, void *userData);"""
484
    func, userData, propagate = ffi.from_handle(handle)
0 ignored issues
show
Bug introduced by
The Instance of _MockFFI does not seem to have a member named from_handle.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
485
    try:
486
        return func(BSP(node), userData)
487
    except BaseException:
488
        propagate(*_sys.exc_info())
489
        return False
490
491
492
__all__ = [_name for _name in list(globals()) if _name[0] != '_']
493