-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add type hints #10
Add type hints #10
Conversation
I didn't look into dependencies. Please let me know how to set up the |
As for now, the getter's return type can't be determined. It's better to leave the return type as `Any` so that one could narrow down the getter's return type to their needs.
Ad e9788e8, please take a look at jaraco/skeleton#97. |
Ad 304e455, I thought of making the |
This PR is part of jaraco/skeleton#98. |
@jaraco waitin' for review! 🚀 |
I don't understand why tests are failing with "ruff: file would be formatted". The ruff formatter isn't yet enabled... or is it. Okay, yes, pytest-enabler 3.0.0 does add |
Doc builds are failing with:
These errors aren't part of the test suite, but can be invoked with These warnings, emitted as errors due to the "nitpicky" setting, are Sphinx's way of trying to indicate that it doesn't have access to the type annotations. This suggests to me that the types should be declared outside the |
Thanks for help with the Ruff error! I looked at the code again and noticed that I could make it better and more accurate. I'll patch my solution soon. I think I also shouldn't use |
I see. I will try with |
I found a successful work-around using nitpicky = True
nitpick_ignore = [
('py:class', 'Self'),
('py:class', '_T'),
('py:obj', 'jaraco.classes.properties._T'),
('py:class', '_ClassPropertyAttribute'),
('py:class', '_GetterCallable'),
('py:class', '_GetterClassMethod'),
('py:class', '_GetterStaticMethod'),
('py:class', '_SetterCallable'),
('py:class', '_SetterClassMethod'),
] This is the preview I deployed from https://github.com/bswck/jaraco.classes/tree/type-hints-nitpick-ignore: https://smokeshow.helpmanual.io/6k37174k0d170s5q0h65/ I personally don't like these interfaces being unlinked, so I guess I will indeed move them out of the |
Important There is a known typing issue when trying to set values of class properties: mypy will often warn that you cannot assign to a method. The current work-around is to Should we note that somewhere? I think a relevant issue in mypy ought to be opened too, unless there is one already. Descriptors defining |
Ah, yes, we need a requirement |
Hmmm, that's weird. I completely removed the |
It might be because I quoted type aliases to defer it from running at runtime... Well, let's try with the deprecated type aliases from |
Ok, I'm honestly disappointed. Getting this to work with Sphinx will:
@jaraco would you be OK with merging code that builds these docs in the end? It's bswck/jaraco.classes@type-hints-nitpick-ignore. |
Rebased onto https://github.com/bswck/jaraco.classes/tree/type-hints-nitpick-ignore. Ready for re-review. class TestClassProperty(metaclass=classproperty.Meta):
@classproperty
@classmethod
def foo(cls) -> str:
return "Test"
reveal_type(TestClassProperty.foo) reveals |
Hmmm, well... I let myself un-make the second arg to |
No need for an extra type for staticmethods, it evaluates to `Callable`
🤷 Ideally, there'd be an upstream issue, but I'll leave it to you to decide if that's worth the investment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for working through all the issues.
The error is easy to silence with |
One more pedantic improvement 😅 |
Closes #9.