Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with get_type_hints(cls.__init__) and refactor #760

Merged
merged 3 commits into from
Feb 19, 2021

Conversation

euresti
Copy link
Contributor

@euresti euresti commented Feb 16, 2021

This fixes #593

I factored out the call to eval(compile... and added a generic _make_method method to remove repeated code.

Pull Request Check List

This is just a friendly reminder about the most common mistakes. Please make sure that you tick all boxes. But please read our contribution guide at least once, it will save you unnecessary review cycles!

If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing left to do. If your pull request is a documentation fix or a trivial typo, feel free to delete the whole thing.

  • Added tests for changed code.
  • New features have been added to our Hypothesis testing strategy.
  • Changes or additions to public APIs are reflected in our type stubs (files ending in .pyi).
    • ...and used in the stub test file tests/typing_example.py.
  • Updated documentation for changed code.
    • New functions/classes have to be added to docs/api.rst by hand.
    • Changes to the signature of @attr.s() have to be added by hand too.
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives. Find the appropriate next version in our __init__.py file.
  • Documentation in .rst files is written using semantic newlines.
  • Changes (and possible deprecations) have news fragments in changelog.d.

If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!

@euresti euresti requested a review from hynek February 16, 2021 17:13
@hynek
Copy link
Member

hynek commented Feb 17, 2021

We totally can switch to exec.

It was only removed by your boss in #87 because it’s a bit ugly re: Python 2.

If it helps you in any way: feel free to re-introduce it!

@euresti
Copy link
Contributor Author

euresti commented Feb 17, 2021

After reading a bunch of docs I think we can leave well enough alone and keep going with compile/eval. Unless @glyph has strong opinions about it now.

So do we think having the correct "globals" on every method is necessary? If so I can factor out the eval/compile into a helper.

@hynek
Copy link
Member

hynek commented Feb 17, 2021

I don’t think that any other method changes it’s signature based on the attributes. However, I think I’d prefer a nice and documented function anyways if it’s not too much trouble!

@euresti
Copy link
Contributor Author

euresti commented Feb 17, 2021

Right. The only other uses of compile/eval are are hash, the cmp methods and the Attributes class creator, which don't have annotations.

I'll try to make a helper anyway just to keep them together.

@euresti euresti marked this pull request as ready for review February 17, 2021 15:41
@euresti euresti changed the title Work in progress: Fix issue with get_type_hints(cls.__init__) Fix issue with get_type_hints(cls.__init__) and refactor Feb 17, 2021
@euresti
Copy link
Contributor Author

euresti commented Feb 17, 2021

I'm not sure why it's saying the tests weren't successful when they were here:

image

@hynek hynek added this to the 21.1.0 milestone Feb 18, 2021
@hynek
Copy link
Member

hynek commented Feb 18, 2021

So since codecov is once again giving us a hard time, I've run it manually and got this missing coverage:

src/attr/_make.py             911      0    463      2    99%   303->305, 1957->1961

Any chance of fixing it? 😇

@euresti
Copy link
Contributor Author

euresti commented Feb 18, 2021

My pleasure.

@hynek hynek merged commit 1499c77 into python-attrs:master Feb 19, 2021
@hynek
Copy link
Member

hynek commented Feb 19, 2021

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deferred type annotations are evaluated in the wrong execution context
2 participants