Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-113978: Ignore warnings on text completion inside REPL#113979

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ambv merged 1 commit intopython:mainfromWolframAlph:supress-completion-warnings
May 21, 2024

Conversation

WolframAlph
Copy link
Contributor

Copy link
Member

@sobolevnsobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe instead we should do this?

» git patchdiff --git Lib/rlcompleter.py Lib/rlcompleter.pyindex 206d6fb511c..62fd2c7fdec 100644--- Lib/rlcompleter.py+++ Lib/rlcompleter.py@@ -176,8 +176,9 @@ def attr_matches(self, text):                 if (word[:n] == attr and                     not (noprefix and word[:n+1] == noprefix)):                     match = "%s.%s" % (expr, word)+                    import types                     if isinstance(getattr(type(thisobject), word, None),-                                  property):+                                  (property, types.GetSetDescriptorType)):                         # bpo-44752: thisobject.word is a method decorated by                         # `@property`. What follows applies a postfix if                         # thisobject.word is callable, but know we know that

It also solves the issue:
Снимок экрана 2024-01-12 в 14 35 59

@WolframAlph
Copy link
ContributorAuthor

Not really sure. My intention was to eliminate all possible warnings during completion (now and in future) no matter where they come from. Maybe it's the only possible path where it can happen but I am not sure since I never dealt with such things. Your solution looks cleaner to me and I believe you have broader context so I leave it up to you to decide.

@sobolevn
Copy link
Member

My thoughs: properties should not evaluate when auto-complete works, so I think that adding an ignore just hides this problem.

So, we should really address the root of this problem: do not execute.co_lnotab property on code objects (and similar types as well).

sunmy2019 reacted with thumbs up emoji

@WolframAlph
Copy link
ContributorAuthor

WolframAlph commentedJan 12, 2024
edited
Loading

properties should not evaluate when auto-complete works

I agree. But is this true only for built-in objects and their properties or user defined as well?
Consider following piece of code:

classD:def__get__(self,_,__):print("evaluated")classC:prop=D()

trying to get suggestions forC. evaluatesprop and prints the message.

@sobolevn
Copy link
Member

We can also try to replacegetattr withinspect.getattr_static

@WolframAlph
Copy link
ContributorAuthor

Some things depend on being evaluated. Usinginspect.getattr_static instead ofgetattr breaks tests.

deftest_attr_matches(self):
# test with builtins namespace
self.assertEqual(self.stdcompleter.attr_matches('str.s'),
['str.{}('.format(x)forxindir(str)
ifx.startswith('s')])
self.assertEqual(self.stdcompleter.attr_matches('tuple.foospamegg'), [])
expected=sorted({'None.%s%s'% (x,
'()'ifx=='__init_subclass__'
else''ifx=='__doc__'
else'(')
forxindir(None)})
self.assertEqual(self.stdcompleter.attr_matches('None.'),expected)
self.assertEqual(self.stdcompleter.attr_matches('None._'),expected)
self.assertEqual(self.stdcompleter.attr_matches('None.__'),expected)
# test with a customized namespace
self.assertEqual(self.completer.attr_matches('CompleteMe.sp'),
['CompleteMe.spam'])
self.assertEqual(self.completer.attr_matches('Completeme.egg'), [])
self.assertEqual(self.completer.attr_matches('CompleteMe.'),
['CompleteMe.mro()','CompleteMe.spam'])
self.assertEqual(self.completer.attr_matches('CompleteMe._'),
['CompleteMe._ham'])
matches=self.completer.attr_matches('CompleteMe.__')
forxinmatches:
self.assertTrue(x.startswith('CompleteMe.__'),x)
self.assertIn('CompleteMe.__name__',matches)
self.assertIn('CompleteMe.__new__(',matches)
withpatch.object(CompleteMe,"me",CompleteMe,create=True):
self.assertEqual(self.completer.attr_matches('CompleteMe.me.me.sp'),
['CompleteMe.me.me.spam'])
self.assertEqual(self.completer.attr_matches('egg.s'),
['egg.{}('.format(x)forxindir(str)
ifx.startswith('s')])

Things like__init_subclass__,__class__,mro, etc...

@ambvambv merged commite03dde5 intopython:mainMay 21, 2024
@lysnikolaoulysnikolaou added topic-replRelated to the interactive shell needs backport to 3.13bugs and security fixes labelsMay 22, 2024
@miss-islington-app
Copy link

Thanks@WolframAlph for the PR, and@ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMay 22, 2024
…onGH-113979)(cherry picked from commite03dde5)Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
@bedevere-app
Copy link

GH-119429 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelMay 22, 2024
ambv pushed a commit that referenced this pull requestMay 22, 2024
…113979) (#119429)(cherry picked from commite03dde5)Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@sobolevnsobolevnsobolevn left review comments

Assignees
No one assigned
Labels
topic-replRelated to the interactive shell
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@WolframAlph@sobolevn@ambv@lysnikolaou

[8]ページ先頭

©2009-2025 Movatter.jp