Skip to content

Commit

Permalink
add Integer traitlet
Browse files Browse the repository at this point in the history
Most int traits are now Integers

Integer differs from Long only in that small `long`s are cast to `int`, rather than
all `int`s being cast to `long`:

    Integer(4L) => 4
    Long(4) => 4L

closes ipythongh-942
  • Loading branch information
minrk committed Nov 13, 2011
1 parent f6b3d8f commit cfee6c0
Show file tree
Hide file tree
Showing 28 changed files with 183 additions and 127 deletions.
2 changes: 1 addition & 1 deletion IPython/config/application.py
Expand Up @@ -34,7 +34,7 @@
)

from IPython.utils.traitlets import (
Unicode, List, Int, Enum, Dict, Instance, TraitError
Unicode, List, Enum, Dict, Instance, TraitError
)
from IPython.utils.importstring import import_item
from IPython.utils.text import indent, wrap_paragraphs, dedent
Expand Down
8 changes: 4 additions & 4 deletions IPython/config/tests/test_application.py
Expand Up @@ -28,7 +28,7 @@
)

from IPython.utils.traitlets import (
Bool, Unicode, Int, Float, List, Dict
Bool, Unicode, Integer, Float, List, Dict
)

#-----------------------------------------------------------------------------
Expand All @@ -37,14 +37,14 @@

class Foo(Configurable):

i = Int(0, config=True, help="The integer i.")
j = Int(1, config=True, help="The integer j.")
i = Integer(0, config=True, help="The integer i.")
j = Integer(1, config=True, help="The integer j.")
name = Unicode(u'Brian', config=True, help="First name.")


class Bar(Configurable):

b = Int(0, config=True, help="The integer b.")
b = Integer(0, config=True, help="The integer b.")
enabled = Bool(True, config=True, help="Enable bar.")


Expand Down
10 changes: 5 additions & 5 deletions IPython/config/tests/test_configurable.py
Expand Up @@ -27,7 +27,7 @@
)

from IPython.utils.traitlets import (
Int, Float, Unicode
Integer, Float, Unicode
)

from IPython.config.loader import Config
Expand All @@ -39,14 +39,14 @@


class MyConfigurable(Configurable):
a = Int(1, config=True, help="The integer a.")
a = Integer(1, config=True, help="The integer a.")
b = Float(1.0, config=True, help="The integer b.")
c = Unicode('no config')


mc_help=u"""MyConfigurable options
----------------------
--MyConfigurable.a=<Int>
--MyConfigurable.a=<Integer>
Default: 1
The integer a.
--MyConfigurable.b=<Float>
Expand All @@ -55,15 +55,15 @@ class MyConfigurable(Configurable):

mc_help_inst=u"""MyConfigurable options
----------------------
--MyConfigurable.a=<Int>
--MyConfigurable.a=<Integer>
Current: 5
The integer a.
--MyConfigurable.b=<Float>
Current: 4.0
The integer b."""

class Foo(Configurable):
a = Int(0, config=True, help="The integer a.")
a = Integer(0, config=True, help="The integer a.")
b = Unicode('nope', config=True)


Expand Down
2 changes: 1 addition & 1 deletion IPython/config/tests/test_loader.py
Expand Up @@ -28,7 +28,7 @@

from IPython.testing.tools import mute_warn

from IPython.utils.traitlets import Int, Unicode
from IPython.utils.traitlets import Unicode
from IPython.config.configurable import Configurable
from IPython.config.loader import (
Config,
Expand Down
4 changes: 2 additions & 2 deletions IPython/core/formatters.py
Expand Up @@ -28,7 +28,7 @@
# Our own imports
from IPython.config.configurable import Configurable
from IPython.lib import pretty
from IPython.utils.traitlets import Bool, Dict, Int, Unicode, CUnicode, ObjectName
from IPython.utils.traitlets import Bool, Dict, Integer, Unicode, CUnicode, ObjectName
from IPython.utils.py3compat import unicode_to_str


Expand Down Expand Up @@ -357,7 +357,7 @@ def dtype_pprinter(obj, p, cycle):
verbose = Bool(False, config=True)

# The maximum width.
max_width = Int(79, config=True)
max_width = Integer(79, config=True)

# The newline character.
newline = Unicode('\n', config=True)
Expand Down
6 changes: 3 additions & 3 deletions IPython/core/history.py
Expand Up @@ -29,7 +29,7 @@
from IPython.testing.skipdoctest import skip_doctest
from IPython.utils import io
from IPython.utils.path import locate_profile
from IPython.utils.traitlets import Bool, Dict, Instance, Int, CInt, List, Unicode
from IPython.utils.traitlets import Bool, Dict, Instance, Integer, List, Unicode
from IPython.utils.warn import warn

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -361,12 +361,12 @@ def _dir_hist_default(self):
output_hist_reprs = Dict()

# The number of the current session in the history database
session_number = CInt()
session_number = Integer()
# Should we log output to the database? (default no)
db_log_output = Bool(False, config=True)
# Write to database every x commands (higher values save disk access & power)
# Values of 1 or less effectively disable caching.
db_cache_size = Int(0, config=True)
db_cache_size = Integer(0, config=True)
# The input and output caches
db_input_cache = List()
db_output_cache = List()
Expand Down
8 changes: 4 additions & 4 deletions IPython/core/interactiveshell.py
Expand Up @@ -74,7 +74,7 @@
from IPython.utils.strdispatch import StrDispatch
from IPython.utils.syspathcontext import prepended_to_syspath
from IPython.utils.text import num_ini_spaces, format_screen, LSString, SList
from IPython.utils.traitlets import (Int, CBool, CaselessStrEnum, Enum,
from IPython.utils.traitlets import (Integer, CBool, CaselessStrEnum, Enum,
List, Unicode, Instance, Type)
from IPython.utils.warn import warn, error, fatal
import IPython.core.hooks
Expand Down Expand Up @@ -226,7 +226,7 @@ class InteractiveShell(SingletonConfigurable, Magic):
Enable magic commands to be called without the leading %.
"""
)
cache_size = Int(1000, config=True, help=
cache_size = Integer(1000, config=True, help=
"""
Set the size of the output cache. The default is 1000, you can
change it permanently in your config file. Setting it to 0 completely
Expand Down Expand Up @@ -277,7 +277,7 @@ class InteractiveShell(SingletonConfigurable, Magic):
def _exiter_default(self):
return ExitAutocall(self)
# Monotonically increasing execution counter
execution_count = Int(1)
execution_count = Integer(1)
filename = Unicode("<ipython console>")
ipython_dir= Unicode('', config=True) # Set to get_ipython_dir() in __init__

Expand Down Expand Up @@ -317,7 +317,7 @@ def _exiter_default(self):
prompts_pad_left = CBool(True, config=True)
quiet = CBool(False, config=True)

history_length = Int(10000, config=True)
history_length = Integer(10000, config=True)

# The readline stuff will eventually be moved to the terminal subclass
# but for now, we can't do that as readline is welded in everywhere.
Expand Down
36 changes: 18 additions & 18 deletions IPython/core/prefilter.py
Expand Up @@ -35,7 +35,7 @@
from IPython.core.splitinput import split_user_input, LineInfo
from IPython.core import page

from IPython.utils.traitlets import List, Int, Any, Unicode, CBool, Bool, Instance
from IPython.utils.traitlets import List, Integer, Any, Unicode, CBool, Bool, Instance
from IPython.utils.text import make_quoted_expr
from IPython.utils.autoattr import auto_attr

Expand Down Expand Up @@ -369,7 +369,7 @@ def prefilter_lines(self, lines, continue_prompt=False):
class PrefilterTransformer(Configurable):
"""Transform a line of user input."""

priority = Int(100, config=True)
priority = Integer(100, config=True)
# Transformers don't currently use shell or prefilter_manager, but as we
# move away from checkers and handlers, they will need them.
shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
Expand Down Expand Up @@ -398,7 +398,7 @@ def __repr__(self):
class AssignSystemTransformer(PrefilterTransformer):
"""Handle the `files = !ls` syntax."""

priority = Int(100, config=True)
priority = Integer(100, config=True)

def transform(self, line, continue_prompt):
m = _assign_system_re.match(line)
Expand All @@ -417,7 +417,7 @@ def transform(self, line, continue_prompt):
class AssignMagicTransformer(PrefilterTransformer):
"""Handle the `a = %who` syntax."""

priority = Int(200, config=True)
priority = Integer(200, config=True)

def transform(self, line, continue_prompt):
m = _assign_magic_re.match(line)
Expand All @@ -435,7 +435,7 @@ def transform(self, line, continue_prompt):
class PyPromptTransformer(PrefilterTransformer):
"""Handle inputs that start with '>>> ' syntax."""

priority = Int(50, config=True)
priority = Integer(50, config=True)

def transform(self, line, continue_prompt):

Expand All @@ -456,7 +456,7 @@ def transform(self, line, continue_prompt):
class IPyPromptTransformer(PrefilterTransformer):
"""Handle inputs that start classic IPython prompt syntax."""

priority = Int(50, config=True)
priority = Integer(50, config=True)

def transform(self, line, continue_prompt):

Expand All @@ -479,7 +479,7 @@ def transform(self, line, continue_prompt):
class PrefilterChecker(Configurable):
"""Inspect an input line and return a handler for that line."""

priority = Int(100, config=True)
priority = Integer(100, config=True)
shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager')
enabled = Bool(True, config=True)
Expand All @@ -501,7 +501,7 @@ def __repr__(self):

class EmacsChecker(PrefilterChecker):

priority = Int(100, config=True)
priority = Integer(100, config=True)
enabled = Bool(False, config=True)

def check(self, line_info):
Expand All @@ -514,7 +514,7 @@ def check(self, line_info):

class ShellEscapeChecker(PrefilterChecker):

priority = Int(200, config=True)
priority = Integer(200, config=True)

def check(self, line_info):
if line_info.line.lstrip().startswith(ESC_SHELL):
Expand All @@ -523,7 +523,7 @@ def check(self, line_info):

class MacroChecker(PrefilterChecker):

priority = Int(250, config=True)
priority = Integer(250, config=True)

def check(self, line_info):
obj = self.shell.user_ns.get(line_info.ifun)
Expand All @@ -535,7 +535,7 @@ def check(self, line_info):

class IPyAutocallChecker(PrefilterChecker):

priority = Int(300, config=True)
priority = Integer(300, config=True)

def check(self, line_info):
"Instances of IPyAutocall in user_ns get autocalled immediately"
Expand All @@ -549,7 +549,7 @@ def check(self, line_info):

class MultiLineMagicChecker(PrefilterChecker):

priority = Int(400, config=True)
priority = Integer(400, config=True)

def check(self, line_info):
"Allow ! and !! in multi-line statements if multi_line_specials is on"
Expand All @@ -566,7 +566,7 @@ def check(self, line_info):

class EscCharsChecker(PrefilterChecker):

priority = Int(500, config=True)
priority = Integer(500, config=True)

def check(self, line_info):
"""Check for escape character and return either a handler to handle it,
Expand All @@ -586,7 +586,7 @@ def check(self, line_info):

class AssignmentChecker(PrefilterChecker):

priority = Int(600, config=True)
priority = Integer(600, config=True)

def check(self, line_info):
"""Check to see if user is assigning to a var for the first time, in
Expand All @@ -604,7 +604,7 @@ def check(self, line_info):

class AutoMagicChecker(PrefilterChecker):

priority = Int(700, config=True)
priority = Integer(700, config=True)

def check(self, line_info):
"""If the ifun is magic, and automagic is on, run it. Note: normal,
Expand All @@ -628,7 +628,7 @@ def check(self, line_info):

class AliasChecker(PrefilterChecker):

priority = Int(800, config=True)
priority = Integer(800, config=True)

def check(self, line_info):
"Check if the initital identifier on the line is an alias."
Expand All @@ -644,7 +644,7 @@ def check(self, line_info):

class PythonOpsChecker(PrefilterChecker):

priority = Int(900, config=True)
priority = Integer(900, config=True)

def check(self, line_info):
"""If the 'rest' of the line begins with a function call or pretty much
Expand All @@ -659,7 +659,7 @@ def check(self, line_info):

class AutocallChecker(PrefilterChecker):

priority = Int(1000, config=True)
priority = Integer(1000, config=True)

def check(self, line_info):
"Check if the initial word/function is callable and autocall is on."
Expand Down
4 changes: 2 additions & 2 deletions IPython/frontend/html/notebook/kernelmanager.py
Expand Up @@ -29,7 +29,7 @@
from IPython.config.configurable import LoggingConfigurable
from IPython.zmq.ipkernel import launch_kernel
from IPython.zmq.kernelmanager import KernelManager
from IPython.utils.traitlets import Instance, Dict, List, Unicode, Float, Int
from IPython.utils.traitlets import Instance, Dict, List, Unicode, Float, Integer

#-----------------------------------------------------------------------------
# Classes
Expand Down Expand Up @@ -196,7 +196,7 @@ class MappingKernelManager(MultiKernelManager):
kernel_argv = List(Unicode)
kernel_manager = Instance(KernelManager)
time_to_dead = Float(3.0, config=True, help="""Kernel heartbeat interval in seconds.""")
max_msg_size = Int(65536, config=True, help="""
max_msg_size = Integer(65536, config=True, help="""
The max raw message size accepted from the browser
over a WebSocket connection.
""")
Expand Down
4 changes: 2 additions & 2 deletions IPython/frontend/html/notebook/notebookapp.py
Expand Up @@ -57,7 +57,7 @@
aliases as ipkernel_aliases,
IPKernelApp
)
from IPython.utils.traitlets import Dict, Unicode, Int, List, Enum, Bool
from IPython.utils.traitlets import Dict, Unicode, Integer, List, Enum, Bool

#-----------------------------------------------------------------------------
# Module globals
Expand Down Expand Up @@ -195,7 +195,7 @@ class NotebookApp(BaseIPythonApplication):
def _ip_changed(self, name, old, new):
if new == u'*': self.ip = u''

port = Int(8888, config=True,
port = Integer(8888, config=True,
help="The port the notebook server will listen on."
)

Expand Down
6 changes: 3 additions & 3 deletions IPython/frontend/qt/console/console_widget.py
Expand Up @@ -20,7 +20,7 @@
from IPython.frontend.qt.rich_text import HtmlExporter
from IPython.frontend.qt.util import MetaQObjectHasTraits, get_font
from IPython.utils.text import columnize
from IPython.utils.traitlets import Bool, Enum, Int, Unicode
from IPython.utils.traitlets import Bool, Enum, Integer, Unicode
from ansi_code_processor import QtAnsiCodeProcessor
from completion_widget import CompletionWidget
from kill_ring import QtKillRing
Expand Down Expand Up @@ -59,7 +59,7 @@ class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):
ansi_codes = Bool(True, config=True,
help="Whether to process ANSI escape codes."
)
buffer_size = Int(500, config=True,
buffer_size = Integer(500, config=True,
help="""
The maximum number of lines of text before truncation. Specifying a
non-positive number disables text truncation (not recommended).
Expand Down Expand Up @@ -112,7 +112,7 @@ def _font_family_default(self):
# Monospace should always exist, no need for a fallback
return 'Monospace'

font_size = Int(config=True,
font_size = Integer(config=True,
help="""The font size. If unconfigured, Qt will be entrusted
with the size of the font.
""")
Expand Down

0 comments on commit cfee6c0

Please sign in to comment.