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

bpo-46571: improvetyping.no_type_check to skip foreign objects#31042

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
JelleZijlstra merged 3 commits intopython:mainfromsobolevn:issue-46571
Feb 19, 2022

Conversation

@sobolevn
Copy link
Member

@sobolevnsobolevn commentedFeb 1, 2022
edited by bedevere-bot
Loading

There are several changes:

  1. We now don't explicitly check for any base / sub types, because new name check covers it
  2. I've also checked thatno_type_check do not modify foreign functions. It was the same as withtypes
  3. I've also coveredexcept TypeError inno_type_check with a simple test case, it was not covered at all
  4. I also felt like addinglambda test is a good idea: becauselambda is a bit of both in class bodies: a function and an assignment

Are there any other cases we want to cover?

https://bugs.python.org/issue46571

@AlexWaygood
Copy link
Member

AlexWaygood commentedFeb 1, 2022
edited
Loading

Here's a slightly evil corner case that this patch doesn't account for:

If I have a moduletyping_test.py, like so:

# typing_test.pyclassA:classAA:foo:int

Then, observe the following behaviour (with your patch applied):

>>>fromtypingimportget_type_hints,no_type_check>>>importtyping_test>>>get_type_hints(typing_test.A.AA){'foo':<class'int'>}>>> @no_type_check...classA:...AA=typing_test.A.AA... ...>>>get_type_hints(typing_test.A.AA){}

We might be able to get around this by looking at the__module__ attribute.

sobolevn reacted with eyes emoji

@sobolevn
Copy link
MemberAuthor

sobolevn commentedFeb 2, 2022
edited
Loading

@AlexWaygood good one! Very evil!

I've addressed this.

@JelleZijlstra I agree that we should also fixclassmethod /staticmethod problem. Because we declare to support all methods, not just instance methods.

The problem is thattypes.MethodType does not support attribute assignment:

>>>classSome:...     @staticmethod...defst(x:int)->int: ......     @classmethod...defcl(cls,y:int)->int: ...>>>Some.st.__no_type_check__=True>>>Some.cl.__no_type_check__=TrueAttributeError:'method'objecthasnoattribute'__no_type_check__'

Ideas?

Moreover, do we need some special@property support?

@AlexWaygood
Copy link
Member

@AlexWaygood good one! Very evil!

I've addressed this.

Doesn't look like you've pushed anything -- did you mean to? :)

@sobolevn
Copy link
MemberAuthor

Doesn't look like you've pushed anything -- did you mean to? :)

Not yet, I am still fightingclassmethod 🙂

AlexWaygood reacted with thumbs up emojiAlexWaygood reacted with laugh emoji

@sobolevn
Copy link
MemberAuthor

Probably

ifisinstance(obj,types.MethodType):obj.__func__.__no_type_check__=True

is the way to go 🤔

Will write some more tests to be sure.

Copy link
Member

@JelleZijlstraJelleZijlstra left a comment

Choose a reason for hiding this comment

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

Looks good.

Do you think this should be backported? I'm leaning no as it's a behavior change and nobody directly complained about the old behavior (looks like you found it while reviewing typing test coverage).

AlexWaygood reacted with thumbs up emoji
Copy link
Member

@gvanrossumgvanrossum left a comment

Choose a reason for hiding this comment

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

Agreed, a backport doesn't seem asked for.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@AlexWaygoodAlexWaygoodAlexWaygood left review comments

@JelleZijlstraJelleZijlstraJelleZijlstra approved these changes

@gvanrossumgvanrossumgvanrossum approved these changes

@Fidget-SpinnerFidget-SpinnerAwaiting requested review from Fidget-Spinner

Assignees

@JelleZijlstraJelleZijlstra

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@sobolevn@AlexWaygood@JelleZijlstra@gvanrossum@the-knights-who-say-ni@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp