summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobert <r-obert@users.noreply.github.com>2017-06-13 22:25:53 +0100
committerGitHub <noreply@github.com>2017-06-13 22:25:53 +0100
commit8d030c3faae899534128c527b3053797cfec0c8d (patch)
tree80ce50398c4dc0463949dc7900ad5cb7c1323805
parentfa67de2f98c3ef00295ebc4ec84b3441d17afa72 (diff)
parenteeda5313f87558ccde83396f0c975eda3127b513 (diff)
downloadpry-8d030c3faae899534128c527b3053797cfec0c8d.tar.gz
Merge pull request #1611 from pry/respond_to-2.4-warnings
improve ruby 2.4 support
-rw-r--r--.travis.yml1
-rw-r--r--CHANGELOG.md15
-rw-r--r--lib/pry.rb3
-rw-r--r--lib/pry/code.rb2
-rw-r--r--lib/pry/commands/edit.rb2
-rw-r--r--lib/pry/commands/ls.rb4
-rw-r--r--lib/pry/commands/ls/constants.rb12
-rw-r--r--lib/pry/config/behavior.rb4
-rw-r--r--lib/pry/forwardable.rb23
-rw-r--r--lib/pry/last_exception.rb4
-rw-r--r--lib/pry/method.rb4
-rw-r--r--lib/pry/output.rb4
-rw-r--r--lib/pry/pry_class.rb2
-rw-r--r--lib/pry/repl.rb4
-rw-r--r--lib/pry/slop.rb2
-rw-r--r--lib/pry/test/helper.rb2
-rw-r--r--lib/pry/wrapped_module.rb4
-rw-r--r--lib/pry/wrapped_module/candidate.rb14
-rw-r--r--spec/commands/edit_spec.rb4
-rw-r--r--spec/method_spec.rb3
-rw-r--r--spec/pry_output_spec.rb3
21 files changed, 74 insertions, 42 deletions
diff --git a/.travis.yml b/.travis.yml
index d8e0c9ea..aaba3066 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,6 +5,7 @@ rvm:
- 2.1
- 2.2
- 2.3.1
+ - 2.4
- ruby-head
- rbx-2
- jruby
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 48960572..3887334f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,10 +1,13 @@
### HEAD
-* Improve completion speed in large applications. [#1588](https://github.com/pry/pry/pull/1588)
-* Pry::ColorPrinter.pp: add `newline` argument and pass it on to PP. [#1603](https://github.com/pry/pry/pull/1603)
-* Use `less` or system pager pager on MS Windows if it is available. [#1512](https://github.com/pry/pry/pull/1512)
-* Add `Pry.configure` as an alternative to the current way of changing configuration options in `.pryrc` files. [#1502](https://github.com/pry/pry/pull/1502)
-* Add `Pry::Config::Behavior#eager_load!` to add a possible workaround for issues like [#1501](https://github.com/pry/pry/issues/1501)
+* Improve Ruby 2.4 support ([#1611](https://github.com/pry/pry/pull/1611)):
+ * Deprecated constants are hidden from `ls` output by default, use the `-d` switch to see them.
+ * Fix warnings that originate in Pry while using the repl.
+* Improve completion speed in large applications. ([#1588](https://github.com/pry/pry/pull/1588))
+* Pry::ColorPrinter.pp: add `newline` argument and pass it on to PP. ([#1603](https://github.com/pry/pry/pull/1603))
+* Use `less` or system pager pager on MS Windows if it is available. ([#1512](https://github.com/pry/pry/pull/1512))
+* Add `Pry.configure` as an alternative to the current way of changing configuration options in `.pryrc` files. ([#1502](https://github.com/pry/pry/pull/1502))
+* Add `Pry::Config::Behavior#eager_load!` to add a possible workaround for issues like ([#1501](https://github.com/pry/pry/issues/1501))
* Remove Slop as a runtime dependency by vendoring v3.4 as Pry::Slop.
People can depend on Slop v4 and Pry at the same time without running into version conflicts. ([#1497](https://github.com/pry/pry/issues/1497))
* Fix auto-indentation of code that uses a single-line rescue ([#1450](https://github.com/pry/pry/issues/1450))
@@ -34,7 +37,7 @@
* Implemented support for CDPATH for ShellCommand ([#1433](https://github.com/pry/pry/issues/1433), [#1434](https://github.com/pry/pry/issues/1434))
* `Pry::CLI.parse_options` does not start Pry anymore ([#1393](https://github.com/pry/pry/pull/1393))
* The gem uses CPU-less platforms for Windows now ([#1410](https://github.com/pry/pry/pull/1410))
-* Add `Pry::Config::Lazy` to make it easier to reimplement `Pry::Config::Default` without knowing its implementation [#1503](https://github.com/pry/pry/pull/1503/)
+* Add `Pry::Config::Lazy` to make it easier to reimplement `Pry::Config::Default` without knowing its implementation ([#1503](https://github.com/pry/pry/pull/1503/))
* Lazy load the config defaults for `Pry.config.history` and `Pry.config.gist`.
### 0.10.1
diff --git a/lib/pry.rb b/lib/pry.rb
index fd33728e..7ccded7a 100644
--- a/lib/pry.rb
+++ b/lib/pry.rb
@@ -2,12 +2,11 @@
# MIT License
#
require 'pp'
-
+require 'pry/forwardable'
require 'pry/input_lock'
require 'pry/exceptions'
require 'pry/helpers/base_helpers'
require 'pry/hooks'
-require 'forwardable'
class Pry
# The default hooks - display messages when beginning and ending Pry sessions.
diff --git a/lib/pry/code.rb b/lib/pry/code.rb
index 9177b39c..fd49f93f 100644
--- a/lib/pry/code.rb
+++ b/lib/pry/code.rb
@@ -338,7 +338,7 @@ class Pry
undef =~
# Check whether String responds to missing methods.
- def respond_to_missing?(name, include_all = false)
+ def respond_to_missing?(name, include_all=false)
''.respond_to?(name, include_all)
end
diff --git a/lib/pry/commands/edit.rb b/lib/pry/commands/edit.rb
index f65cb23e..d0208fdf 100644
--- a/lib/pry/commands/edit.rb
+++ b/lib/pry/commands/edit.rb
@@ -157,7 +157,7 @@ class Pry
case opts[:i]
when Range
(_pry_.input_array[opts[:i]] || []).join
- when Fixnum
+ when Integer
_pry_.input_array[opts[:i]] || ""
else
raise Pry::CommandError, "Not a valid range: #{opts[:i]}"
diff --git a/lib/pry/commands/ls.rb b/lib/pry/commands/ls.rb
index 9f0e68f2..42b83d9f 100644
--- a/lib/pry/commands/ls.rb
+++ b/lib/pry/commands/ls.rb
@@ -61,7 +61,9 @@ class Pry
" " * 32 << "Constants that are pending autoload? are also shown (in yellow)"
opt.on :i, :ivars, "Show instance variables (in blue) and class variables (in bright blue)"
opt.on :G, :grep, "Filter output by regular expression", :argument => true
-
+ if Object.respond_to?(:deprecate_constant)
+ opt.on :d, :dconstants, "Show deprecated constants"
+ end
if jruby?
opt.on :J, "all-java", "Show all the aliases for methods from java (default is to show only prettiest)"
end
diff --git a/lib/pry/commands/ls/constants.rb b/lib/pry/commands/ls/constants.rb
index 3db81624..6889075f 100644
--- a/lib/pry/commands/ls/constants.rb
+++ b/lib/pry/commands/ls/constants.rb
@@ -3,15 +3,16 @@ require 'pry/commands/ls/interrogatable'
class Pry
class Command::Ls < Pry::ClassCommand
class Constants < Pry::Command::Ls::Formatter
+ DEPRECATED_CONSTANTS = [:Fixnum, :Bignum, :TimeoutError, :NIL, :FALSE, :TRUE]
include Pry::Command::Ls::Interrogatable
-
def initialize(interrogatee, no_user_opts, opts, _pry_)
super(_pry_)
@interrogatee = interrogatee
@no_user_opts = no_user_opts
@default_switch = opts[:constants]
@verbose_switch = opts[:verbose]
+ @dconstants = opts.dconstants?
end
def correct_opts?
@@ -26,8 +27,17 @@ class Pry
private
+ def show_deprecated_constants?
+ @dconstants == true
+ end
+
def format(mod, constants)
constants.sort_by(&:downcase).map do |name|
+ if Object.respond_to?(:deprecate_constant) and
+ DEPRECATED_CONSTANTS.include?(name) and
+ !show_deprecated_constants?
+ next
+ end
if const = (!mod.autoload?(name) && (mod.const_get(name) || true) rescue nil)
if (const < Exception rescue false)
color(:exception_constant, name)
diff --git a/lib/pry/config/behavior.rb b/lib/pry/config/behavior.rb
index 719dd5e6..081c3828 100644
--- a/lib/pry/config/behavior.rb
+++ b/lib/pry/config/behavior.rb
@@ -186,8 +186,8 @@ module Pry::Config::Behavior
end
end
- def respond_to_missing?(key, include_private=false)
- key?(key) or @default.respond_to?(key) or super(key, include_private)
+ def respond_to_missing?(key, include_all=false)
+ key?(key) or @default.respond_to?(key) or super(key, include_all)
end
private
diff --git a/lib/pry/forwardable.rb b/lib/pry/forwardable.rb
new file mode 100644
index 00000000..bc432842
--- /dev/null
+++ b/lib/pry/forwardable.rb
@@ -0,0 +1,23 @@
+class Pry
+ module Forwardable
+ require 'forwardable'
+ include ::Forwardable
+
+ #
+ # Since Ruby 2.4, Forwardable will print a warning when
+ # calling a method that is private on a delegate, and
+ # in the future it could be an error: https://bugs.ruby-lang.org/issues/12782#note-3
+ #
+ # That's why we revert to a custom implementation for delegating one
+ # private method to another.
+ #
+ def def_private_delegators(target, *private_delegates)
+ private_delegates.each do |private_delegate|
+ define_method(private_delegate) do |*a, &b|
+ instance_variable_get(target).__send__(private_delegate, *a, &b)
+ end
+ end
+ class_eval { private(*private_delegates) }
+ end
+ end
+end
diff --git a/lib/pry/last_exception.rb b/lib/pry/last_exception.rb
index 2841113d..8bf84b5a 100644
--- a/lib/pry/last_exception.rb
+++ b/lib/pry/last_exception.rb
@@ -23,8 +23,8 @@ class Pry::LastException < BasicObject
end
end
- def respond_to_missing?(name, include_private = false)
- @e.respond_to?(name)
+ def respond_to_missing?(name, include_all=false)
+ @e.respond_to?(name, include_all)
end
#
diff --git a/lib/pry/method.rb b/lib/pry/method.rb
index 1e209222..6ce69c88 100644
--- a/lib/pry/method.rb
+++ b/lib/pry/method.rb
@@ -461,8 +461,8 @@ class Pry
# @param [String, Symbol] method_name
# @return [Boolean]
- def respond_to?(method_name)
- super or @method.respond_to?(method_name)
+ def respond_to?(method_name, include_all=false)
+ super or @method.respond_to?(method_name, include_all)
end
# Delegate any unknown calls to the wrapped method.
diff --git a/lib/pry/output.rb b/lib/pry/output.rb
index cc72503f..c2be6df0 100644
--- a/lib/pry/output.rb
+++ b/lib/pry/output.rb
@@ -35,8 +35,8 @@ class Pry::Output
@boxed_io.__send__(name, *args, &block)
end
- def respond_to_missing?(*a)
- @boxed_io.respond_to?(*a)
+ def respond_to_missing?(m, include_all=false)
+ @boxed_io.respond_to?(m, include_all)
end
def decolorize_maybe(str)
diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb
index 1609f376..95a574f9 100644
--- a/lib/pry/pry_class.rb
+++ b/lib/pry/pry_class.rb
@@ -5,7 +5,7 @@ class Pry
LOCAL_RC_FILE = "./.pryrc"
class << self
- extend Forwardable
+ extend Pry::Forwardable
attr_accessor :custom_completions
attr_accessor :current_line
attr_accessor :line_buffer
diff --git a/lib/pry/repl.rb b/lib/pry/repl.rb
index dba4bf5a..e70130a4 100644
--- a/lib/pry/repl.rb
+++ b/lib/pry/repl.rb
@@ -1,8 +1,6 @@
-require 'forwardable'
-
class Pry
class REPL
- extend Forwardable
+ extend Pry::Forwardable
def_delegators :@pry, :input, :output
# @return [Pry] The instance of {Pry} that the user is controlling.
diff --git a/lib/pry/slop.rb b/lib/pry/slop.rb
index a7792bdf..b11c37b1 100644
--- a/lib/pry/slop.rb
+++ b/lib/pry/slop.rb
@@ -332,7 +332,7 @@ class Pry::Slop
# Override this method so we can check if an option? method exists.
#
# Returns true if this option key exists in our list of options.
- def respond_to_missing?(method_name, include_private = false)
+ def respond_to_missing?(method_name, include_all=false)
options.any? { |o| o.key == method_name.to_s.chop } || super
end
diff --git a/lib/pry/test/helper.rb b/lib/pry/test/helper.rb
index 2ef8289b..e71536a0 100644
--- a/lib/pry/test/helper.rb
+++ b/lib/pry/test/helper.rb
@@ -102,7 +102,7 @@ def pry_eval(*eval_strs)
end
class PryTester
- extend Forwardable
+ extend Pry::Forwardable
attr_reader :pry, :out
diff --git a/lib/pry/wrapped_module.rb b/lib/pry/wrapped_module.rb
index c17124ea..1514af11 100644
--- a/lib/pry/wrapped_module.rb
+++ b/lib/pry/wrapped_module.rb
@@ -150,8 +150,8 @@ class Pry
wrapped.send(method_name, *args, &block)
end
- def respond_to?(method_name)
- super || wrapped.respond_to?(method_name)
+ def respond_to?(method_name, include_all=false)
+ super || wrapped.respond_to?(method_name, include_all)
end
# Retrieve the source location of a module. Return value is in same
diff --git a/lib/pry/wrapped_module/candidate.rb b/lib/pry/wrapped_module/candidate.rb
index e35c0356..67ef1925 100644
--- a/lib/pry/wrapped_module/candidate.rb
+++ b/lib/pry/wrapped_module/candidate.rb
@@ -1,5 +1,4 @@
require 'pry/helpers/documentation_helpers'
-require 'forwardable'
class Pry
class WrappedModule
@@ -10,7 +9,7 @@ class Pry
class Candidate
include Pry::Helpers::DocumentationHelpers
include Pry::CodeObject::Helpers
- extend Forwardable
+ extend Pry::Forwardable
# @return [String] The file where the module definition is located.
attr_reader :file
@@ -22,15 +21,12 @@ class Pry
# Methods to delegate to associated `Pry::WrappedModule
# instance`.
- private_delegates = [:lines_for_file, :method_candidates,
- :yard_docs?]
-
- public_delegates = [:wrapped, :module?, :class?, :name, :nonblank_name,
+ private_delegates = [:lines_for_file, :method_candidates, :yard_docs?, :name]
+ public_delegates = [:wrapped, :module?, :class?, :nonblank_name,
:number_of_candidates]
- def_delegators :@wrapper, *(private_delegates + public_delegates)
- private(*private_delegates)
- public(*public_delegates)
+ def_delegators :@wrapper, *public_delegates
+ def_private_delegators :@wrapper, *private_delegates
# @raise [Pry::CommandError] If `rank` is out of bounds.
# @param [Pry::WrappedModule] wrapper The associated
diff --git a/spec/commands/edit_spec.rb b/spec/commands/edit_spec.rb
index 39d1226b..24ff6321 100644
--- a/spec/commands/edit_spec.rb
+++ b/spec/commands/edit_spec.rb
@@ -388,8 +388,8 @@ describe "edit" do
end
it "should edit a multi-line expression as it occupies one line of _in_" do
- pry_eval "class Fixnum\n def invert; -self; end\nend", "edit -i 1"
- expect(@contents).to eq "class Fixnum\n def invert; -self; end\nend\n"
+ pry_eval "class #{1.class}\n def invert; -self; end\nend", "edit -i 1"
+ expect(@contents).to eq "class #{1.class}\n def invert; -self; end\nend\n"
end
it "should not work with a filename" do
diff --git a/spec/method_spec.rb b/spec/method_spec.rb
index d315c6d4..2317a96b 100644
--- a/spec/method_spec.rb
+++ b/spec/method_spec.rb
@@ -415,7 +415,8 @@ describe Pry::Method do
end
it "should not include singleton classes of numbers" do
- expect(Pry::Method.resolution_order(4)).to eq Pry::Method.instance_resolution_order(Fixnum)
+ target_class = 4.class
+ expect(Pry::Method.resolution_order(4)).to eq Pry::Method.instance_resolution_order(target_class)
end
it "should include singleton classes for classes" do
diff --git a/spec/pry_output_spec.rb b/spec/pry_output_spec.rb
index 9430dc8d..ad4f47df 100644
--- a/spec/pry_output_spec.rb
+++ b/spec/pry_output_spec.rb
@@ -116,9 +116,8 @@ describe Pry do
describe "custom non-IO object as $stdout" do
it "does not crash pry" do
old_stdout = $stdout
- custom_io = Class.new { def write(*) end }.new
pry_eval = PryTester.new(binding)
- expect(pry_eval.eval("$stdout = custom_io", ":ok")).to eq(:ok)
+ expect(pry_eval.eval("$stdout = Class.new { def write(*) end }.new", ":ok")).to eq(:ok)
$stdout = old_stdout
end
end